Skip to content

Commit

Permalink
fix translation and grammar mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Feb 25, 2024
1 parent fbda7d0 commit e819040
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 46 deletions.
4 changes: 2 additions & 2 deletions rust/derive/src/def_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![];
Expand Down
2 changes: 1 addition & 1 deletion rust/locales/zh-CN.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
22 changes: 11 additions & 11 deletions rust/src/base/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ 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;
}

#[derive(Debug)]
pub struct RuntimeError {
content: Box<dyn ErrorContent>,
context: Box<dyn ErrorContext>,
info: ErrorInfo,
}

Expand All @@ -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()
);
Expand All @@ -82,11 +82,11 @@ impl Display for RuntimeError {
}

impl RuntimeError {
pub fn new(content: Box<dyn ErrorContent>, info: ErrorInfo) -> RuntimeError {
pub fn new(context: Box<dyn ErrorContext>, info: ErrorInfo) -> RuntimeError {
// if info.message != "" {
// panic!("develop debug use");
// }
RuntimeError { content, info }
RuntimeError { context, info }
}
}

Expand All @@ -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 {
""
}
Expand All @@ -119,9 +119,9 @@ impl ErrorContent for LightFakeError {
}
}

impl LightFakeContent {
pub fn new() -> LightFakeContent {
LightFakeContent {}
impl LightFakeContext {
pub fn new() -> LightFakeContext {
LightFakeContext {}
}
}

Expand Down
14 changes: 7 additions & 7 deletions rust/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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),
Expand Down Expand Up @@ -330,7 +330,7 @@ pub struct Compiler {
input: Box<dyn TokenIo<Item = char>>,
pub const_pool: ValuePool,
option: Option,
content: Content,
context: Context,
}

impl Compiler {
Expand All @@ -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),
}
}
_ => {
Expand All @@ -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),
}
}

Expand All @@ -375,7 +375,7 @@ impl Compiler {

#[inline]
pub fn report_compiler_error<T>(&self, info: ErrorInfo) -> RunResult<T> {
Err(RuntimeError::new(Box::new(self.content.clone()), info))
Err(RuntimeError::new(Box::new(self.context.clone()), info))
}
}

Expand Down
6 changes: 3 additions & 3 deletions rust/src/compiler/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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())
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions rust/src/compiler/token.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
}
'}' => {
Expand All @@ -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)
}
']' => {
Expand All @@ -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)
}
')' => {
Expand Down Expand Up @@ -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();
}
}
}
Expand Down Expand Up @@ -773,15 +773,15 @@ impl TokenLex<'_> {
return self.next_token();
}
'\n' => {
self.compiler_data.content.add_line();
self.compiler_data.context.add_line();
return self.next_token();
}
'#' => {
// 注释
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' {
Expand Down Expand Up @@ -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)),
Expand Down
22 changes: 11 additions & 11 deletions rust/src/tvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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,
}
Expand Down Expand Up @@ -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(_) => {}
}
Expand Down Expand Up @@ -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),
}
}
Expand All @@ -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,
}
}
Expand All @@ -187,14 +187,14 @@ impl<'a> Vm<'a> {
fn throw_err_info<T>(&self, info: RuntimeResult<T>) -> RunResult<T> {
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 {
Expand Down Expand Up @@ -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)),
));
}
Expand Down
2 changes: 1 addition & 1 deletion rust/src/tvm/function.rs
Original file line number Diff line number Diff line change
@@ -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,
}
Expand Down

0 comments on commit e819040

Please sign in to comment.