-
Notifications
You must be signed in to change notification settings - Fork 21
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
MAR backend #9
Comments
Hello. Thank you so much for exploring my compiler, it means a lot to me that someone would want to use it for a personal project. Let me address your questions one by one.
Yes, I plan to add a README for each of the individual folders in the project for contributors' sake, especially the
Yes, adding debug information could be done. Thankfully, function names are only replaced with ID's in the final and most simple layer of IR in I think the proper way is to feed the
You're absolutely right. When I wrote the examples, I was mostly trying to debug the compiler after adding some feature. I think it would be helpful to add a header comment for each file explaining its purpose, and more comments in the code.
I would love to! I couldn't seem to find a branch with a Rust target implementation on your github, though. Have you pushed it yet? |
Thanks for the response. Im still finishing the implementation to work for all examples after that i will explore the architecture for the Target trait to see if I can start a draft. Yeah the debug information should not be used by the backend to generate code. Just to provide some debug information in the result so its easier to figure out how the generated code maps to the original source. I think its good practise to use a unqiue id. I made a fork of oakc and made a branch MAR-Backend. You can visit it here https://github.com/kevinramharak/oakc/tree/mar/master/src/target/mar.rs. It has a |
That's absolutely wonderful. I'm really excited to see how well your new Target implementation goes. If you have any questions, I can definitely help. How is it working so far? Are there any problems? |
I have every example working except for The current live version has a broken console so I can't link it yet, but I even got I am keeping up to date with upstream, so the new sign opcode should work soon. I am also planning to try and get a gh-pages branch running where I compile the compiler (or at least enough of it) to web assembly so people won't have to install rust just to take a look. So you could write your oak in a textarea, get your resulting assembly code and copy it into the editor on the MAR site. But that just something im planning on to try and get more people hooked by having a easy entrypoint to the project. Simple screen shot of running |
That's absolutely incredible. With the #[heap(512)]
fn main() {
let size = 32;
let x: &char = alloc(size);
// This should be something around 500 something depending on
// how many variables are used in the included `std.ok` functions.
// The more variables defined in those functions, the larger the stack is,
// and the further away from address 0 the heap begins on the memory tape.
putnumln(x);
} I found, using programs somewhat similar to this, that my Also, with respect to the webassembly implementation, an alternative I'd also love to hear your perspective on #10 :) |
Okay i got the Im going to put the webassembly branch off until I have at least the core functionality working. Tnx for the headers. I think I can hack a demo once I put a few hours in to it. Since MAR has a fixed binary size of 128k (64k x 16-bit words) I have not implented the heap directive yet. Right now it dumps data at offset 0, code after data and then a label at the end of the code. This means everything between that label and the stack pointer (which starts at |
Maybe we should add a |
That seems like a good solution for now. |
I can't believe every other example works though, thats absolutely incredible. I'm throroughly impressed that someone else was able to add another backend, which compiles to psuedo 8086 assembly, no less. I think that's solid proof that this project accomplishes what I've always wanted from the compilers I've previously written. I'm optimistic about where this project is going. I wonder if your MAR backend could be adapted to real 8086 assembly to run on DOS.... |
Well I think the setup of I'm not sure about adapting to real 8086. It is quite a level up and it is missing a lot of features that a linker usually does. I'm sure someone can. The author of MAR is back on the project to get it up to speed again so i'm hoping to get a solid version working soon, preferably with a low entry point github pages setup to show people how easy it is. After that i'm hoping the POC can get people's attention and people get interested in writing their own backends. |
So i got sick of not being able to debug the One issue i was having was that MAR has no module system nor imports and dependecies. So I got the idea to use the oak compiler itself to generate the I plan on generating the Take a look at the branch at https://github.com/kevinramharak/oakc/tree/mar/master |
@adam-mcdaniel After some refactoring to make the code easier to debug I am happy to announce that the brainfuck interpreter works. Also on the note of x86 target I noticed this fork https://github.com/Not-Nik/oakc. |
This is unbelievable!!!! Does the new MAR implementation work with the automatic memory management pull request?? I'm very interested to see a demo or video of the MAR version in action. Also, the x86 implementation @Not-Nik is working on looks AWESOME. I had no idea someone was working on another backend!!!!!!! Im excited :) |
Ngl I kinda left this fork to just be some waypoint on how a possible x86 backend could look. With the addition |
The examples in For example: #[std]
// this seems to be a valid function name, really usefull for namespacing
fn C::strlen(string: &char) -> num {
__ffi_pass_arg_by_reference!(string as &void);
__c_strlen!();
return __ffi_pass_return_value!() as num;
}
#[doc("Copies `length` amount of words from the location pointed to by `source` to the memory location pointed to by `destination`.")]
fn C::memcpy(destination: &void, source: &void, length: num) -> &void {
// implement it in oak
for (let i = 0; i < length; i += 1) {
(destination as &num)[i] = (source as &num)[i];
}
return destination;
// if we need performance/less code size we can implement it in assembly and make this function a wrapper for it instead
// __ffi_pass_arg_by_value!(length);
// __ffi_pass_arg_by_reference!(source);
// __ffi_pass_arg_by_reference!(destination);
// __c_memccpy!();
// return __ffi_pass_return_value!() as &void;
}
fn main() {
let string = "Hello World!";
let length = C::strlen(string);
putnumln(length);
} The I'll try to record a demo soon enough. Its a bit hard to show it because im working on a non-released branch of Much Assembly Required that has a debugger (lifesaver @simon987) and interrupts implemented. Once those are released into the main branch you can just checkout my fork, compile a program with the |
Hi,
Thank you for this amazing project. I have been trying to write a C compiler for Much Assembly Required for a while but never seem to get past the beast called the C standard.
This project allows me to focus on finishing a source to source translation without getting stuck on the details.
You can see my attempt at implementing the backend here: https://github.com/kevinramharak/oakc/tree/mar/master
I do have a few questions tough:
std.ok
is very opaque at the moment. Maybe i could even help write some of the docs?Target
trait? Debugging the generated assembly with 0 information from the original context is hard. I understand the HIR and MIR alllow for these abstractions, but preserving function names to thefn_definition
would already be a step in the right direction.refer.ok
prints out:
Is it intended that
inc
has copy behaviour?If you have spare time I would appreciate it if you could look review my rust implementation as the compiler does not like the way i generate unique labels for while loops. Any nudges in the right direction would be appreciated.
The text was updated successfully, but these errors were encountered: