Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. Basecode
  2. --------
  3. A new programming language that I'm designing.
  4. The bootstrap compiler is written in C++17.
  5. Eventually we'll be moving the compiler toolchain into Basecode Alpha itself.
  6.  
  7. ## 1 - Basecode Language Alpha (v1)
  8.  
  9. - a low-level language
  10. - basic language subset, but advanced enough to implement a compiler (see 3)
  11. - @todo list more language features
  12.  
  13. ## 2- Compiler and Interpreter for Basecode Language in C++17
  14.  
  15. ### Phase 1 - From Source to Bytecode
  16.  
  17. source = "program in basecode lang ... ";
  18. tokens = lexer(source);
  19. ast = parser(tokens);
  20. bytecode = compiler(ast);
  21. uses bytecode_assembler(ast);
  22.  
  23. The compiler walks the AST and creates bytecode for BasecodeVM.
  24. BasecodeVM is a bytecode interpreter implementing our own instruction set architecture.
  25.  
  26. ## Phase 2 - From Bytecode to Program Execution
  27.  
  28. Now, that we have bytecode, we have the following options:
  29.  
  30. ### We can do a direct interpretation of bytecode:
  31.  
  32. interpretedProgram = BasecodeVM(bytecode);
  33.  
  34. Having an interpreter is nice for testing and debugging.
  35.  
  36. ### We can save bytecode for later interpretation (and as cache):
  37.  
  38. bytecode_file = bytecode_emitter(bytecode);
  39.  
  40. The emitter embeds the bytecode and some metadata (e.g. a "bytecode version" for identification)
  41. and produces a structured bytecode file. This bytecode file is then runnable by the BasecodeVM.
  42.  
  43. ## We can generate native code from bytecode and emit the executable binary format for the target:
  44.  
  45. native_code = native_codegen(bytecode, target);
  46. based on target uses
  47. - assembler_x86(bytecode);
  48. - assembler_x86_64(bytecode);
  49. - assembler_arm|risc(bytecode);
  50.  
  51. binary = binary-emitter(native_code, target);
  52. based on target uses
  53. - binary_writer_elf
  54. - binary_writer_dwarf
  55. - binary_writer_pecoff
  56.  
  57. This is a cross-compiler, because we are targetting multiple instruction set architectures / platforms.
  58.  
  59. In the end we can compile "helloWorld.bc" with the "Basecode-Compiler-Written-In-C++" to "helloWorld.exe".
  60.  
  61. When the C++ based compiler is able to compile Basecode v1,
  62. i will eventually implement the compiler for Basecode in Basecode itself.
  63.  
  64. ## 3 - Compiler for Basecode Language in Basecode (self-hosting)
  65.  
  66. The goal is to compile "helloWorld.bc" with "Basecode-Compiler-Written-In-Basecode" to "helloWorld.exe".
  67.  
  68. ## 4 - Improve Basecode Language
  69.  
  70. I want to create a meta programming language.
  71. A meta programming language enables you to create your own language easily.
  72. It's a language to create other languages.
  73.  
  74. Basecode enables you to
  75. - define your new language as an EBNF grammar
  76. - ...
  77. (
  78. - generate a lexer/parser for this language
  79. - generate an AST
  80. - generate AST-Walkers/Visitors
  81. - do rule based text-transformation?
  82. - define bytecodes for your language
  83. - interpret bytecodes (which means running your language interpreted)
  84. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement