Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Basecode
- --------
- A new programming language that I'm designing.
- The bootstrap compiler is written in C++17.
- Eventually we'll be moving the compiler toolchain into Basecode Alpha itself.
- ## 1 - Basecode Language Alpha (v1)
- - a low-level language
- - basic language subset, but advanced enough to implement a compiler (see 3)
- - @todo list more language features
- ## 2- Compiler and Interpreter for Basecode Language in C++17
- ### Phase 1 - From Source to Bytecode
- source = "program in basecode lang ... ";
- tokens = lexer(source);
- ast = parser(tokens);
- bytecode = compiler(ast);
- uses bytecode_assembler(ast);
- The compiler walks the AST and creates bytecode for BasecodeVM.
- BasecodeVM is a bytecode interpreter implementing our own instruction set architecture.
- ## Phase 2 - From Bytecode to Program Execution
- Now, that we have bytecode, we have the following options:
- ### We can do a direct interpretation of bytecode:
- interpretedProgram = BasecodeVM(bytecode);
- Having an interpreter is nice for testing and debugging.
- ### We can save bytecode for later interpretation (and as cache):
- bytecode_file = bytecode_emitter(bytecode);
- The emitter embeds the bytecode and some metadata (e.g. a "bytecode version" for identification)
- and produces a structured bytecode file. This bytecode file is then runnable by the BasecodeVM.
- ## We can generate native code from bytecode and emit the executable binary format for the target:
- native_code = native_codegen(bytecode, target);
- based on target uses
- - assembler_x86(bytecode);
- - assembler_x86_64(bytecode);
- - assembler_arm|risc(bytecode);
- binary = binary-emitter(native_code, target);
- based on target uses
- - binary_writer_elf
- - binary_writer_dwarf
- - binary_writer_pecoff
- This is a cross-compiler, because we are targetting multiple instruction set architectures / platforms.
- In the end we can compile "helloWorld.bc" with the "Basecode-Compiler-Written-In-C++" to "helloWorld.exe".
- When the C++ based compiler is able to compile Basecode v1,
- i will eventually implement the compiler for Basecode in Basecode itself.
- ## 3 - Compiler for Basecode Language in Basecode (self-hosting)
- The goal is to compile "helloWorld.bc" with "Basecode-Compiler-Written-In-Basecode" to "helloWorld.exe".
- ## 4 - Improve Basecode Language
- I want to create a meta programming language.
- A meta programming language enables you to create your own language easily.
- It's a language to create other languages.
- Basecode enables you to
- - define your new language as an EBNF grammar
- - ...
- (
- - generate a lexer/parser for this language
- - generate an AST
- - generate AST-Walkers/Visitors
- - do rule based text-transformation?
- - define bytecodes for your language
- - interpret bytecodes (which means running your language interpreted)
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement