Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

[WIP] Add proper Repl #488

Closed
wants to merge 7 commits into from
Closed

[WIP] Add proper Repl #488

wants to merge 7 commits into from

Conversation

Stupremee
Copy link
Contributor

@Stupremee Stupremee commented Jul 24, 2020

This PR will introduce a proper Repl using rustyline and the jit backend.

Only merge if #493 is merged
Resolves #372

- Move binaries into `bin` folder
- History support
- Command hinting
- Matching bracket highlighting
Copy link
Owner

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good skeleton to add more features onto :)

src/bin/repl/helper.rs Outdated Show resolved Hide resolved
src/bin/repl/helper.rs Show resolved Hide resolved
src/bin/repl/mod.rs Outdated Show resolved Hide resolved
src/bin/repl/mod.rs Show resolved Hide resolved
src/bin/repl/commands.rs Outdated Show resolved Hide resolved
src/bin/repl/helper.rs Outdated Show resolved Hide resolved
src/bin/repl/mod.rs Outdated Show resolved Hide resolved
src/bin/swcci.rs Outdated Show resolved Hide resolved
- repl history is now saved in data_dir
- Any expression will be wrapped in a function
- This function will be transmute'd into a rust function and then be called.
- NOTE: Code doesn't compile right now.
Copy link
Owner

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick look, I haven't seen all of it.

if !start.starts_with(PREFIX) {
return None;
}
let start = &start[1..];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure you need to abstract over the prefix, but if you do, be consistent:

Suggested change
let start = &start[1..];
let start = &start[PREFIX.len()..];

src/bin/repl/mod.rs Outdated Show resolved Hide resolved
}),
storage_class: data::StorageClass::Extern,
qualifiers: Default::default(),
id: saltwater::InternedStr::get_or_intern("execute"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
id: saltwater::InternedStr::get_or_intern("execute"),
id: "execute".into(),

Comment on lines 166 to 167
// FIXME: Currently doesn't work. Just make insert() pub?
symbol: fun.insert(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the reason I make this private was because I was thinking about parsing and didn't want people to accidentally add a new identifier ... but it does seem like that would be a major use case for any programmatic use. I'm fine with making it public :)

Comment on lines +182 to +186
// FIXME: error_handler is private so this doesn't work right now.
// Please review and propose a solution.
// if let Some(err) = analyzer.error_handler.pop_front() {
// return Err(err);
// }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, there isn't actually a way to get errors from PureAnalyzer.

@pythondude325 I think we could add an errors() method here? Where it just returns mem::take(&mut self.error_handler)?

src/bin/swcc.rs Outdated
@@ -554,7 +554,7 @@ mod backtrace {

#[cfg(feature = "salty")]
fn play_scream() -> Result<(), ()> {
const SCREAM: &[u8] = include_bytes!("data/R2D2-Scream.ogg");
const SCREAM: &[u8] = include_bytes!("../data/R2D2-Scream.ogg");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const SCREAM: &[u8] = include_bytes!("../data/R2D2-Scream.ogg");
const SCREAM: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "data/R2D2-Scream.ogg")));

- Add errors method to ErrorHandler
- Make `Variable::insert` pub
Comment on lines +25 to +32
macro_rules! execute {
($fun:ident, $ty:path, $action:expr) => {
$action(unsafe {
let execute: unsafe extern "C" fn() -> $ty = std::mem::transmute($fun);
execute()
});
};
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used like

execute!(fun, bool, |b| println!("=> {}", b)),

I think it would be easier and simpler to do println!("=> {}", execute!(fun, bool)), which means you don't need $action or to create a new closure.

Type::Float => execute!(fun, f32, |f| println!("=> {}", f)),
Type::Double => execute!(fun, f64, |f| println!("=> {}", f)),

Type::Char(_) => execute!(fun, char, |c| println!("=> {}", c)),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look quite right ... in Rust, char is a unicode scalar character which is represented as 4 bytes. In C, it's an arbitrary byte, which could be invalid utf8 (0xff).

Suggested change
Type::Char(_) => execute!(fun, char, |c| println!("=> {}", c)),
Type::Char(_) => execute!(fun, u8, |c| println!("=> {}", if c.is_ascii() { c as char } else { `hex::encode(&[c]) })),

https://docs.rs/hex/0.4.2/hex/fn.encode.html

Comment on lines +153 to +156
Type::Void => unsafe {
let execute: unsafe extern "C" fn() = std::mem::transmute(fun);
execute()
},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Type::Void => unsafe {
let execute: unsafe extern "C" fn() = std::mem::transmute(fun);
execute()
},
Type::Void => execute!(fun, (), |_| {}),

@Stupremee Stupremee marked this pull request as draft August 17, 2020 00:24
@Stupremee
Copy link
Contributor Author

I have to reopen because I accidentally deleted my fork (:sweat_smile:)

@Stupremee Stupremee closed this Sep 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use rustyline for REPL
2 participants