Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the interpreter stdout/stderr/stdin agnostic #561

Open
1 of 12 tasks
CohenArthur opened this issue May 2, 2022 · 2 comments
Open
1 of 12 tasks

Make the interpreter stdout/stderr/stdin agnostic #561

CohenArthur opened this issue May 2, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@CohenArthur
Copy link
Member

CohenArthur commented May 2, 2022

In order to reach more platforms such as WASM or micro controllers, it would be nice to move away from the current implementation which relies on {e}println and the standard library's file reading abstraction. Instead, we should focus some of our efforts on adding two traits (with a default implementation) which would allow the interpreter to run on other platforms provided they implement that trait.

The ideal API for "libjinko" users (such as the interpreter) would be something like that:

- let mut ctx = Context::new();
+ let mut ctx = Context::<DefaultReader, WasmWriter>::new();
  • Add a Reader/Input trait
    • Add a method to read a file
    • Add a method to read a string

In the case of platforms without a file system, or where interactive user input is not possible, the trait could have default implementations for these methods in order to not burden someone using libjinko.

  • Add a Writer/Output trait

    • Add a method to write to an equivalent of stdout
    • Add a method to write to an equivalent of stderr
  • Add default StdWriter and StdReader types which implement Writer and Reader using existing stdlib functions, such as fs::read_to_string, println!(), eprintln!()

  • Remove reading/writing without the trait throughout the jinko library

    • In the Incl instruction, files are read and parsed through fs::read_to_string()
    • Errors are emitted using eprintln!()
    • The parser reads a file using fs::read_to_string
    • There might be other places where this is the case

Ideally, this should allow us to compile the jinko library in a no_std + alloc environment. We could think about developing a tiny no_std repl example to test this.

We should not bother about FFI at this point, even though this issue clearly targets platforms where libffi might not be available.

@CohenArthur CohenArthur added the enhancement New feature or request label May 2, 2022
@Skallwar
Copy link
Member

Skallwar commented May 5, 2022

The ideal API for "libjinko" users (such as the interpreter) would be something like that:

- let mut ctx = Context::new();
+ let mut ctx = Context::<DefaultReader, WasmWriter>::new();

After some tests, having a generic context have a HUGE domino effect on the codebase. So I will go the Box<dyn Reader> route

@Skallwar
Copy link
Member

First (draft) PR landed #569

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants