Giter VIP home page Giter VIP logo

dafcompiler's People

Contributors

haved avatar

Stargazers

 avatar

dafcompiler's Issues

Move source file folders to make more sense

The src/parsing/ast/ folder shouldn't really be inside parsing/, as the ast/ is used long after parsing. Same thing goes for semantic/. Basically just move folders out of parsing/ and into src/
Then almost every header include must be updated, and CMakeLists.txt must change BLOB paths.

Binary search for tokens in the lexer

Right now we use strcmp between the text and a list of tokens. This is awful, as we do string comparison with every text token before we realize it is an identifier, and we could quite easily achieve O(log n) speed.

Make a map from string to TOKEN_TYPE and use it in the Lexer.

Give identifiers integer values in the lexer to reduce string memory management

Definitions, Function parameters and variables all have std::string fields. These take up space in the objects, but more importantly aren't shared. In a compiler you'd expect most identifiers to be used many times, however we currently store them once or twice per use. Comparison of strings is also slower when you have to compare char lists, as opposed to single integers.

Implementation
The idea is to not have a text field in the Token struct, but to instead have an integer indexing a global identifier table. The Lexer will then upon tokenizing an identifier use a hash map to reuse identifier ids. When parsing then needs to store the identifier used, only the integer id is stored. It takes less space and can be copied to other objects in constant time. When an error message needs the actual string, just ask the global table.

Make better script for building and running tests

At the moment there are three scripts at varying levels of functionality. They are all in the CompilerTests folder. I'd prefer to have one script for all, with e.g. the build directory being specified once but used for both compiling and testing. This script should be the preferred way of building both debug and release builds, and should pass the correct variables to cmake.

Wanted functionality

Usage: buildScript.py <options>
Options:
--buildDir <buildDir>    Specify the folder in which we build. Default: "DebugBuild"
--cmakeDir <cmakeDir>    Specify the folder where CMakeLists.txt is. Default: "Compiler"
--X86Only <true|false>   Don't link for all LLVM targets. Default: "true"
-W <none|all|pedentic>   Print out warnings? Default:"pedantic"
-O <s|0|1|2|none>        Optimization level. Default "none"
-g <true|false>          Build with -g? Default "true"
-r --release             Changes a bunch of defaults and changes cmake build type
--extraCMakeArgs         <string with extra CMake parameters>
--extraMakeArgs          <string with extra make parameters> Default: "-j3"
--extraCppFlags          <string with extra compiler flags>
--extraLinkerFlags       <string with extra linker flags>

--tests                           Enables testing of the newly compiled binary (if we got so far)
--testFolder <testFolder>         Where to look for tests. Default: "CompilerTests"
--testFilter <testFilter>         Only test files that fit the given regex. Default: "^\w+\.daf$"
--testDafOutput <testingDafO>     Specify where the .o from the DafCompiler is put. Default: "Testing/dafOutput.o"
--testCppFile <testingCppFile>    Specify what C++ file is used to bootstrap daf code. Default: "Testing/dafMainCaller.cpp"
--testCppOutput <testingCppO>     Specify where the C++ binary will be placed. Default:"Testing/dafMainCaller.o"
--testBinaryOutput <binaryOutput> Specify where the binary will be put. Default: "Testing/outputBinary"

Changes done to defaults by --release

  • buildDir = "ReleaseBuild"
  • X86Only = "false"
  • W = "all"
  • O = "2"
  • g = false
  • disables the DAF_DEBUG macro

Note: We don't give CMAKE any CMAKE_BUILD_TYPE, as I'm not sure what that does.
If you really want it, use --extraCMakeArgs

How testing works

The testing is very basic, and only consists of compiling the one daf file, linking it with a compiled C++ file and finally running it, looking at its exit code. If it's not 0, the test failed.

Use memory pools for objects that won't ever be deleted

We use unique pointers everywhere in the compiler to reference other objects, but we never delete these objects. You could potentially throw out a function body once its code is generated, but then you'd throw out everything in the body. Having a memory pool would mean de-allocating all at once.

We might paint ourselves into a corner with this, but having an easy way of changing allocator is needed either way. Aka. Don't stop using unique pointers just because we don't delete it. Knowing ownership is still useful aka when doing makeConcrete on your fields

Test every error message

Do a grep after ERROR and FATAL_ERROR, make a spreadsheet or something, then make testcases for every error message and add it to the sheet. If the message is poorly worded, improve it. We should also aim for consistency in error messages, make a style guide.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.