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

Adds a Ruby backend #84

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open

Conversation

dospunk
Copy link
Contributor

@dospunk dospunk commented Aug 27, 2020

No description provided.

@adam-mcdaniel
Copy link
Owner

Whoa!!!!!! I'm absolutely ecstatic. You've written almost half of our backends now!!!

As an outsider who has implemented Oak for multiple targets, what are some of the strange bugs that you see sometimes while developing a backend? Is the backend code easy to port? What's been your overall experience with implementing the typescript and ruby backends?

@adam-mcdaniel adam-mcdaniel added the backend specific Related to the implementation of a specific backend label Aug 27, 2020
@dospunk
Copy link
Contributor Author

dospunk commented Aug 27, 2020

TypeScript and Ruby were both fairly easy to implement. The hardest part of both was implementing the getch function, since neither language has a built in version, but other than that the std and core code is very easy to port. Implementing a new backend takes about an afternoon, maybe less.

The most annoying part of the process is having to modify multiple Rust files to add a new backend. In bin.rs, you have to add in the use statement, the new flag, and the if statement for whether the flag was found. In lib.rs you have to add in a use statement, and in target/mod.rs you have to add the mod statement and the use statement. If there were a way to streamline that process a little bit, that would be awesome.

I also started work on a Python backend, but quickly hit a dead end. Because of the way that begin_while and end_while work, any language that uses significant whitespace to denote blocks is impossible to implement. If there were only ever one level of indentation it would be easy to work around, but the loops within functions and loops within loops would necessitate some sort of counter to keep track of the indentation level. I tried to hack around with it a bit, but I don't understand Rust well enough to get it working.

@adam-mcdaniel
Copy link
Owner

Thats good to hear!! Also, with respect to the Python backend, you could use a static mut INDENT_LEVEL: i32 to keep track of the current indent level. I THINK this would work, anyways.

@dospunk
Copy link
Contributor Author

dospunk commented Aug 27, 2020

I'll give that a shot!

@dospunk
Copy link
Contributor Author

dospunk commented Oct 24, 2020

So the static mut idea for indentation level unfortunately didn't work, as static mut is apparently unsafe

@kevinramharak
Copy link
Contributor

It is indeed 'unsafe' but that is just because Rust wants to be able to reason about the variables and its access in a multithreading environment. You can wrap code using this value in unsafe {} blocks to be able to use it.

@dospunk
Copy link
Contributor Author

dospunk commented Oct 25, 2020

It is indeed 'unsafe' but that is just because Rust wants to be able to reason about the variables and its access in a multithreading environment. You can wrap code using this value in unsafe {} blocks to be able to use it.

The problem is you can't use unsafe code in a safe function. Unless I'm missing something, which is not unlikely, introducing this one piece of unsafe code would cause a decent chunk of the program to be unsafe just to use it.

@kevinramharak
Copy link
Contributor

You can look at this commit kevinramharak@c1727cb#diff-a0d44f3f45a877f81e862f4806d19f4c7b8f026afd68f98e5a1eb74b0a6f71ca to see how I used to use static without having to mark whole functions as unsafe.
You could instead use a struct to keep track of your state during code generation. This does require you to change bin.rs to instantiate your target just a bit different from other targets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend specific Related to the implementation of a specific backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants