Update version (v0.2.4)

A crash problem with file input has been fixed.
This commit is contained in:
Shunsuke Shibayama 2022-08-17 00:48:19 +09:00
parent 76df45e412
commit c79fcd5dbe
9 changed files with 37 additions and 19 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "erg" name = "erg"
version = "0.2.3" version = "0.2.4"
description = "The Erg programming language" description = "The Erg programming language"
authors = ["Shunsuke Shibayama <sbym1346@gmail.com>"] authors = ["Shunsuke Shibayama <sbym1346@gmail.com>"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
@ -31,9 +31,9 @@ japanese = [
] ]
[dependencies] [dependencies]
erg_common = { version = "0.2.3", path = "./compiler/erg_common" } erg_common = { version = "0.2.4", path = "./compiler/erg_common" }
erg_parser = { version = "0.2.3", path = "./compiler/erg_parser" } erg_parser = { version = "0.2.4", path = "./compiler/erg_parser" }
erg_compiler = { version = "0.2.3", path = "./compiler/erg_compiler" } erg_compiler = { version = "0.2.4", path = "./compiler/erg_compiler" }
# [workspace] # [workspace]
# member = ["cm", "dyne"] # member = ["cm", "dyne"]

View file

@ -1,6 +1,6 @@
[package] [package]
name = "erg_common" name = "erg_common"
version = "0.2.3" version = "0.2.4"
description = "A common components library of Erg" description = "A common components library of Erg"
authors = ["Shunsuke Shibayama <sbym1346@gmail.com>"] authors = ["Shunsuke Shibayama <sbym1346@gmail.com>"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"

View file

@ -303,7 +303,8 @@ fn expect_block(src: &str) -> bool {
|| src.ends_with("=>") || src.ends_with("=>")
} }
/// this trait implements REPL (Read-Eval-Print-Loop) automatically /// This trait implements REPL (Read-Eval-Print-Loop) automatically
/// The `exec` method is called for file input, etc.
pub trait Runnable: Sized { pub trait Runnable: Sized {
type Err: ErrorDisplay; type Err: ErrorDisplay;
type Errs: MultiErrorDisplay<Self::Err>; type Errs: MultiErrorDisplay<Self::Err>;
@ -313,6 +314,7 @@ pub trait Runnable: Sized {
fn finish(&mut self); // called when the :exit command is received. fn finish(&mut self); // called when the :exit command is received.
fn clear(&mut self); fn clear(&mut self);
fn eval(&mut self, src: Str) -> Result<String, Self::Errs>; fn eval(&mut self, src: Str) -> Result<String, Self::Errs>;
fn exec(&mut self) -> Result<(), Self::Errs>;
fn ps1(&self) -> String { fn ps1(&self) -> String {
">>> ".to_string() ">>> ".to_string()
@ -330,13 +332,7 @@ pub trait Runnable: Sized {
let mut instance = Self::new(cfg); let mut instance = Self::new(cfg);
let res = match instance.input() { let res = match instance.input() {
Input::File(_) | Input::Pipe(_) | Input::Str(_) => { Input::File(_) | Input::Pipe(_) | Input::Str(_) => {
match instance.eval(instance.input().read()) { instance.exec()
Ok(s) => {
println!("{s}");
Ok(())
}
Err(e) => Err(e),
}
} }
Input::REPL => { Input::REPL => {
let output = stdout(); let output = stdout();

View file

@ -1,6 +1,6 @@
[package] [package]
name = "erg_compiler" name = "erg_compiler"
version = "0.2.3" version = "0.2.4"
description = "Centimetre: the Erg compiler" description = "Centimetre: the Erg compiler"
authors = ["Shunsuke Shibayama <sbym1346@gmail.com>"] authors = ["Shunsuke Shibayama <sbym1346@gmail.com>"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
@ -15,8 +15,8 @@ debug = [ "erg_common/debug", "erg_parser/debug" ]
japanese = [ "erg_common/japanese", "erg_parser/japanese" ] japanese = [ "erg_common/japanese", "erg_parser/japanese" ]
[dependencies] [dependencies]
erg_common = { version = "0.2.3", path = "../erg_common" } erg_common = { version = "0.2.4", path = "../erg_common" }
erg_parser = { version = "0.2.3", path = "../erg_parser" } erg_parser = { version = "0.2.4", path = "../erg_parser" }
[lib] [lib]
path = "lib.rs" path = "lib.rs"

View file

@ -130,6 +130,10 @@ impl Runnable for Compiler {
self.code_generator.clear(); self.code_generator.clear();
} }
fn exec(&mut self) -> Result<(), Self::Errs> {
todo!()
}
fn eval(&mut self, src: Str) -> Result<String, CompileErrors> { fn eval(&mut self, src: Str) -> Result<String, CompileErrors> {
let codeobj = self.compile(src, "eval")?; let codeobj = self.compile(src, "eval")?;
Ok(codeobj.code_info()) Ok(codeobj.code_info())

View file

@ -1,6 +1,6 @@
[package] [package]
name = "erg_parser" name = "erg_parser"
version = "0.2.3" version = "0.2.4"
description = "The Erg parser" description = "The Erg parser"
authors = ["mtshiba <sbym1346@gmail.com>"] authors = ["mtshiba <sbym1346@gmail.com>"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
@ -14,7 +14,7 @@ debug = [ "erg_common/debug" ]
japanese = [ "erg_common/japanese" ] japanese = [ "erg_common/japanese" ]
[dependencies] [dependencies]
erg_common = { version = "0.2.3", path = "../erg_common" } erg_common = { version = "0.2.4", path = "../erg_common" }
[lib] [lib]
path = "lib.rs" path = "lib.rs"

View file

@ -40,6 +40,10 @@ impl Runnable for LexerRunner {
#[inline] #[inline]
fn clear(&mut self) {} fn clear(&mut self) {}
fn exec(&mut self) -> Result<(), Self::Errs> {
todo!()
}
fn eval(&mut self, src: Str) -> Result<String, LexerRunnerErrors> { fn eval(&mut self, src: Str) -> Result<String, LexerRunnerErrors> {
let lexer = Lexer::from_str(src); let lexer = Lexer::from_str(src);
if cfg!(feature = "debug") { if cfg!(feature = "debug") {

View file

@ -296,6 +296,10 @@ impl Runnable for ParserRunner {
#[inline] #[inline]
fn clear(&mut self) {} fn clear(&mut self) {}
fn exec(&mut self) -> Result<(), Self::Errs> {
todo!()
}
fn eval(&mut self, src: Str) -> Result<String, ParserRunnerErrors> { fn eval(&mut self, src: Str) -> Result<String, ParserRunnerErrors> {
let ast = self.parse_from_str(src)?; let ast = self.parse_from_str(src)?;
Ok(format!("{ast}")) Ok(format!("{ast}"))

View file

@ -1,10 +1,11 @@
use std::fs::remove_file;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::net::TcpStream; use std::net::TcpStream;
use std::thread::sleep; use std::thread::sleep;
use std::time::Duration; use std::time::Duration;
use erg_common::config::{ErgConfig, Input, BUILD_INFO, SEMVER}; use erg_common::config::{ErgConfig, Input, BUILD_INFO, SEMVER};
use erg_common::python_util::exec_py; use erg_common::python_util::{exec_py, exec_pyc};
use erg_common::str::Str; use erg_common::str::Str;
use erg_common::traits::Runnable; use erg_common::traits::Runnable;
@ -82,6 +83,15 @@ impl Runnable for DummyVM {
self.compiler.clear(); self.compiler.clear();
} }
fn exec(&mut self) -> Result<(), Self::Errs> {
let src = self.input().read();
self.compiler
.compile_and_dump_as_pyc(src, "o.pyc", "exec")?;
exec_pyc("o.pyc");
remove_file("o.pyc").unwrap();
Ok(())
}
fn eval(&mut self, src: Str) -> Result<String, CompileErrors> { fn eval(&mut self, src: Str) -> Result<String, CompileErrors> {
self.compiler self.compiler
.compile_and_dump_as_pyc(src, "o.pyc", "eval")?; .compile_and_dump_as_pyc(src, "o.pyc", "eval")?;