3 ms·
This is really impressive. Thank you for sharing. Writing a language and compiler is a large project. I wanted to get something working fast so I started writi
by samsquire 4y ago
This is really impressive. Thank you for sharing.
Writing a language and compiler is a large project. I wanted to get something working fast so I started writing an switch based interpreter. I even use plain strings for instructions and a list of HashMaps for instruction arguments. I figure I can turn it into a bytecode interpreter at a later date.
My codegen for my higher level language is for the interpreter I wrote. Not amd64 or arm.
My interpreter is multithreaded and is integrated with a simple message passing actor API where each thread can have mailboxes to send data or jump instructions.
This allows threads to send messages to other threads and ask them to do things. I implemented this behaviour with a "send", "sendcode", "receive", "receivecode" instructions that either send or check a mailbox for a message and then jump to a label or PC defined by the message. This is pseudo actors. I also have a userspace lightweight scheduler that multiplexes N lightweight threads over M kernel threads and if I combined them together I could have a Golang style runtime that is true actors.
Does anybody know if any compilers are embeddable?
One of my ideas is to borrow the JIT compiler idea from HolyC and keep the AST in memory and referenceable by every expression. Then you can write code to generate or modify AST nodes.
Can GCC be run in a server mode without writing a C file?
I was thinking of writing a transpile to C that compiles and executes at runtime. How do you load an .o file for execution? You need a linker. How do you begin executing an .o file? I think you can load the data into a buffer and cast the buffer to a void function pointer and execute it. This is a pseudo JIT compiler.
https://GitHub.com/samsquire/multiversion-concurrency-control https://GitHub.com/samsquire/multiversion-concurrency-contro...
- stefanos82 4y agoHow about using TinyC Compiler [1]? Personally I use it within my Vim editor with a mapped key to take advantage the `-run` flag and also you can use it as a script with `#!` if you like. [1] https://repo.or.cz/w/tinycc.git https://repo.or.cz/w/tinycc.git
- cxr 4y ago> Does anybody know if any compilers are embeddable?¶ One of my ideas is to borrow the JIT compiler idea from HolyC and keep the AST in memory and referenceable by every expression. Then you can write code to generate or modify AST nodes.¶ Can GCC be run in a server mode without writing a C file?¶ I was thinking of writing a transpile to C that compiles and executes at runtime. Sounds like you want TCC: > Compile and execute C source directly. No linking or assembly necessary. <http://www.tinycc.org/ http://www.tinycc.org/> > TCCBOOT, a hack where TCC loads and boots a Linux kernel from source in about 10 seconds. That is to say, it is a "boot loader" that reads Linux kernel source code from disk, writes executable instructions to memory, and begins running it. <https://en.wikipedia.org/wiki/Tiny_C_Compiler https://en.wikipedia.org/wiki/Tiny_C_Compiler>