4 ms·
Ask HN: A C compiler in a microkernel in a 406 line js CPU emulator. What next?
I made up a 14 instruction CPU specification: http://recc.robertelder.org/op-cpu.txt
I wrote a C compiler for a very large subset (not all) of C89 for this CPU: https://github.com/RobertElderSoftware/recc
I wrote emulators for the CPU in 4 different languages: https://github.com/RobertElderSoftware/recc/tree/master/emulators
I wrote bare bones microkernel: https://github.com/RobertElderSoftware/recc/tree/master/kernel
I can cross-compile the preprocessor, lexer, parser and code generator and run them inside a kernel task, which runs inside the CPU emulators for javascript, python, java, and C (but it is currently super slow): http://recc.robertelder.org/compile-demo/
I'm looking for feedback on what direction to go in next. What would you like to see most?
Directions I can go in:
- Fully client side C compiler and IDE
- Full access to parse tree, static analysis with rich html annotations for errors
- For example, if a function call has arguments that don't match the prototype, show a detailed graphic demonstrating that the arguments don't fit into the function
- Write a proper shell for the kernel
- CPU Emulators for more languages
- Make the compiler produce faster code (it is currently anti-optimized for code simplicity)
- Implement currently unsupported C features (float, double, union, goto, K&R C style functions, ...)
- Work toward having better static analysis (warnings) than GCC or CLANG (but only for C89)
- Write blog posts (about what?)
- Work toward compiling the Linux Kernel
- Create learning tools to help visualize the OS and program stack as the program executes (In addition to showing stack values, provide type annotations via background colours/graphics eg. (0x10000 <= unsigned int))
- Static analysis for MISRA C
- A web based visual tool/animation that shows you every step of how the C preprocessor works
- Other ideas
Project Home: http://recc.robertelder.org/
- deleted 11y ago[deleted]
- chatmasta 11y agoUh, maybe it is a learning exercise? Are you always this much of a dick?
- CyberFonic 11y agoDidn't intend my reply to be critical. Was actually seeking answers. To avoid further distress comment has been deleted.
- altruizine 11y agoWow! Quite an achievement over a wide range of CS fields. :-) The direction to go from here really depends on what you want to achieve for yourself. Do you want to maximize the breadth of your knowledge? Then how about an RTL implementation of a CPU that implements your spec? Going for static analysis or developing an IDE would also have that benefit. Do you want your tools to be useful beyond being a toy / learning experience? Then I would go for feature completeness in the C compiler. Also, a debugger would be needed. I quite like the minimalism of your approach. How about a single-page spec for a CPU with an MMU? :-) (Then you could actually tackle a real Linux port instead of being limited to uClinux. But I'd refrain from trying to port any Linux kernel right now because you'd have to extend your compiler and tool chain quite a bit; Linux is written in GCC, not C.) How about running your compiler as a JIT compiler?