haved / dafcompiler Goto Github PK
View Code? Open in Web Editor NEWThe compiler for the daf language, eventually
License: Other
The compiler for the daf language, eventually
License: Other
We should replace all printSignature() with proper overrides of printConcretableInfo
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.
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.
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.
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.
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"
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
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.
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
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.