Skip to content

Commit

Permalink
hello world成功输出
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Feb 1, 2024
1 parent b4b9be7 commit c6fef9f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
11 changes: 11 additions & 0 deletions rust/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ impl Float {
for _ in 0..len {
float_part /= 10.0;
}
for _ in 0..self.zero {
float_part /= 10.0;
}
self.front as f64 + float_part
}
}
Expand Down Expand Up @@ -188,6 +191,14 @@ impl ValuePool {
for i in &self.const_ints {
ret.intpool[*i.1] = *i.0;
}
ret.floatpool.resize(self.const_floats.len(), 0.0);
for i in &self.const_floats {
ret.floatpool[*i.1] = i.0.to_float();
}
ret.stringpool.resize(self.const_strings.len(), "".to_string());
for i in &self.const_strings {
ret.stringpool[*i.1] = (i.0).clone();
}
ret
}
}
Expand Down
4 changes: 2 additions & 2 deletions rust/src/compiler/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ impl<'a> AstBuilder<'a> {
ExprGen!(expr1, expr1_, expr2, TokenType::And => Opcode::And);
ExprGen!(expr, expr_, expr1, TokenType::Or => Opcode::Or);

pub fn return_static_data(self) -> StaticData {
self.token_lexer.compiler_data.const_pool.store_val_to_vm();
pub fn return_static_data(mut self) -> StaticData {
self.staticdata.constpool = self.token_lexer.compiler_data.const_pool.store_val_to_vm();
self.staticdata
}

Expand Down
28 changes: 18 additions & 10 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,32 @@ use std::error::Error;
struct Args {
#[command(subcommand)]
mode: Commands,
#[arg()]
files: Vec<String>,
}

#[derive(Debug, Subcommand)]
enum Commands {
Build { optimize: bool },
Build {
#[arg(short, long, default_value_t=false)]
optimize: bool,
#[arg()]
files: Vec<String>
},
Tshell {},
Update {},
Run { optimize: bool },
Run {
#[arg(short, long, default_value_t=false)]
optimize: bool,
#[arg()]
files: Vec<String>
},
}

pub fn run() -> Result<(), Box<dyn Error>> {
let cli = Args::parse();
match cli.mode {
Commands::Build { optimize: opt } => {
for i in cli.files {
tools::compile(compiler::Option::new(opt, compiler::InputSource::File(i)));
Commands::Build { optimize: opt, files:files} => {
for i in files {
tools::compile(compiler::Option::new(false, compiler::InputSource::File(i)));
}
}
Commands::Tshell {} => {
Expand All @@ -47,9 +55,9 @@ pub fn run() -> Result<(), Box<dyn Error>> {
}
Ok(_) => {}
},
Commands::Run { optimize: opt } => {
for i in cli.files {
match tools::run::run(compiler::Option::new(opt, compiler::InputSource::File(i))) {
Commands::Run { optimize: opt, files:files } => {
for i in files {
match tools::run::run(compiler::Option::new(false, compiler::InputSource::File(i))) {
Ok(_) => {}
Err(c) => {
eprintln!("{}", c);
Expand Down
3 changes: 2 additions & 1 deletion rust/src/tvm/stdlib/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{base::error::RunResult, tvm::DynaData};

pub fn tvm_print(dydata: &mut DynaData) -> RunResult<()> {
print!("win!");
let obj = dydata.obj_stack.pop();
print!("{}", obj.unwrap());
Ok(())
}

0 comments on commit c6fef9f

Please sign in to comment.