nikgalanop / edsger Goto Github PK
View Code? Open in Web Editor NEWΜεταγλωττιστής για τη γλώσσα Edsger στα πλαίσια του μαθήματος των Μεταγλωττιστών. (Ροή Λ, 8ο Εξάμηνο, ΣΗΜΜΥ ΕΜΠ, 2022)
Μεταγλωττιστής για τη γλώσσα Edsger στα πλαίσια του μαθήματος των Μεταγλωττιστών. (Ροή Λ, 8ο Εξάμηνο, ΣΗΜΜΥ ΕΜΠ, 2022)
To write:
Up until now, we've interpreted the following statements from the specification:
p.7
Οι τύποι
int
καιdouble
ονομάζονται αριθμητικοί τύποι.
p.10
Οι τελεστές
<
,>
,<=
και>=
υλοποιούν τις σχέσεις ανισότητας μεταξύ αριθμών ή δεικτών. Το αποτέλεσμα είναι τύπουbool
. Τα τελούμενα πρέπει να είναι του ίδιου τύπου. Αν είναι αριθμητικά, η σύγκριση γίνεται βάσει των αριθμητικών τους τιμών. Αν είναι τύπουbool
, η σύγκριση γίνεται θεωρώντας ότιfalse < true
. Τέλος, αν είναι δείκτες, η σύγκριση έχει νόημα μόνο όταν τα τελούμενα περιέχουν διευθύνσεις αντικείμενων που βρίσκονται στον ίδιο μονοδιάστατο πίνακα και γίνεται βάσει της σχετικής θέσης αυτών των αντικειμένων μέσα στον πίνακα.
as that comparison between char
s is not supposed to be implemented. The testcases 160-qsort.eds
& 164-rel.eds
(check #59) assume it is. We could implement it.
If we have a file named A which includes B and B includes A, imagine the following scenario:
./lexer < A (We "lose" the information that we are reading from A)
Unnamed A includes B
B includes A (A is perceived as non "seen" since redirection caused loss of information)
A includes B
We have to cast the null pointer to the appropriate pointer type, wherever needed.
Some Edsger implementations in OCaml:
Something that I noticed in the specification is that the example programs do not need the concept of a nesting link. Our program msquare.eds
is the one that does need it, afaic. If we struggle implementing nesting links or something like that, we could simply resort to changing the semantic analysis as following:
The only variables that a function can access outside of its scope must be global variables.
doc/README.md
.Maybe (?) find a library or a method to tidy up "flag" arguments. (Maybe check RWOCaml for more details.)
A pointer can be mutable but it can "point" to somewhere immutable. According to C++ you
can "delete" a static array via a pointer, but in the runtime you are informed about memory corruption.
void test (int a);
void test1 (int b) {
test (b); // Even if not used in main, this is problematic.
}
void main () {
return;
}
Expressions in array declarations have to be of type int, but must be evaluated to a constant positive int
ex. int a[5 + 8]
Write necessary functions to print the AST.
Use sprintf.
@el18177 Reporting all bugs that we faced concerning the OCaml lexer implementation, in this issue.
I suggest that we allow conversion between bool <-> char <-> int <-> double
and a' pointer <-> b' pointer
but not between pointers and "arithmetic" types.
Handle the exception better and return more descriptive messages.
./edsger test.eds
/usr/bin/ld: /tmp/test-0a81eb.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: failed to set dynamic section sizes: bad value
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
Error: Clang produced an error during the linking phase. Check above for more details
• Compiled Successfully: ✗
In case we include correctly a file and it does not exist, the behavior of our lexical analyser is to terminate due to the following exception:
Fatal error: exception Sys_error("non-existent-file: No such file or directory")
.
If we don't want such behaviour, we must handle this exception.
When a file includes itself, do not reinclude it.
Check some LLVM resources in #15.
Fix the newer lambda lifting implementation on the cg_testing
branch.
We currently do not handle properly the case where \0
appears inside a string because \0
is not used in OCaml.
I maybe need to add the flag --x86-asm-syntax
when calling llc
to ensure that we produce x86 assembly
Edit: I just saw that llc
maybe optimizes by default in level 2, if -O0
is not specified. I should check that.
Make sure that the lexer constructs a T_constchar instance properly. (Lexer.mll, Line 167)
Impementation of the lexical analyser in C++ with the usage of "flex".
Should we try to check if we actually delete dynamically allocated memory in sem. analysis? Codegen? Or is it something that can only be implemented in runtime?
Study about LLVM (#28) and start writing some basic codegen for Edsger.
Fix it to not build a phi node. What to return in this case?
Note to myself to remember to remove the flag --infer from the menhir call in our Makefile, when I actually implement the AST.
Maybe change codegen_body
to continue with codegen_stmt
UNTIL either the ast_stmt
list is empty or can_add_terminator ()
is no longer true.
Since we implemented the lexer to use stacks, we are not able to "call the buffer" to provide us with the last lexeme because the stack is completely popped before the final call to the lexeme function.
Maybe use Menhir to produce a .messages file with meaningful syntax error messages?
When we make a reference out of something I guess that we should make the "pointer" that is the result of that reference mutable.
However, when we dereference something eg. a pointer to an immutable array, should the resulting pointer that points to the immutable array be mutable or not? (It's a decision that we should make since arrays are "weird" to say the least in C :) )
I checked the LLVM OCaml API for emitting assembly (specifically the modules Llvm_X86, Llvm_target.TargetMachine and Llvm_target.Target) and also checked the llc
source code.
I think the easier choice is to use the llc
immediately. Should we do this via a bash script or via OCaml and the Sys Module?
If someone does not have llc
on their env, how should we make the path change easy?
Edit: Apparently llc
is not available in Windows, just letting you know.
Some notes about the testcases that mr. Sagonas sent us:
103-ar.eds
: Have not seen that thoroughly yet. (Hopefully solved by dce21b9.)129-fwd.eds
: We've previously assumed that we only need to declare functions in our CG Symbol Table only for linking purposes (thus for declarations in the outer scope). This is not true when some nested declarations are involved in mutual recursion. (Solved by aea13b9.)160-qsort.eds
:
qsort(...)
& doqsort(...)
accept a pointer to a string-like (constant string or array of characters). However, these functions are called with a constant string as an argument. It makes sense that doqsort
results in Segmentation Fault
when the program attempts to alter the contents of that (constant in this case) string-like. I believe that our compiler behaves properly. (Changed nothing.)164-rel.eds
: Same issue pretty much with 160-qsort.eds
. We've assumed that we cannot compare characters. (Changed nothing.)Implementation of the lexical analyser in OCaml with the usage of ocamllex.
The documentation about readChar
refers to the previous implementation where whitespaces were discarded.
Check the functionality of the parser and suggest corrections wherever they are needed.
NULL
can be assigned to a pointer of any type.add_definition
& add_declaration
) or scrap this feature completely.#include <stdio.h>
void f (int x) {
printf("x = %d\n", x);
}
// f(a,b,c,d) -> "fun_f_" ^ List.iter ( ^ ) str_of_type params
// fun_f_intcharint
int f (int &x) {
printf("x + 1 = %d\n", x + 1);
}
int main()
{
f(4);
return 0;
}
byref
parameters)int trunc (double d);
int round (double d);
main(){
fun1(){
fdef(){}
fdef();
}
fun2(){
fdef(){ fun1(); }
}
}
When I try to explicitly return NULL
in an non-int
function, it fails. This is because in the specific case of a return
statement, we do not do the necessary type conversion.
How should we approach the building process?
Have the prebuilt binaries in case someone wants to just have the necessary files and only describe the process of building from source?
dune build
for the compiler executable inside /edsger/src
, make
inside the /src/lib
and just move the header files and the static library wherever the edsger source files are?
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.