Giter Club home page Giter Club logo

edsger's People

Contributors

el18177 avatar nikgalanop avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

edsger's Issues

Allow comparison between `char` ASCII codes

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 chars is not supposed to be implemented. The testcases 160-qsort.eds & 164-rel.eds (check #59) assume it is. We could implement it.

Cyclical #include problem

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

A nested functions discussion

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.

build_gep vs build_in_bounds_gep

@el18177 Have you understood the difference between build_gep & build_in_bounds_gep? Which one should I use? I have not understood the explanation of the inbounds keyword that is provided here.

Clean up CLI parameters

Maybe (?) find a library or a method to tidy up "flag" arguments. (Maybe check RWOCaml for more details.)

Things to reconsider in runtime

  • Should make sure that the pointer of e, actually points somewhere and not in a NULL value.
  • Check for memory corruption.

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.

  • Check for segmentation faults. (Out of bounds array accesses)
  • Check for valid dynamic allocations.
  • Declaring a function that is used somewhere but is never defined. (Check the example below)
void test (int a);
void test1 (int b) {
    test (b); // Even if not used in main, this is problematic.
}
void main () {
   return;
}
  • Since it is hard to consider whether or not a return statement will actually return something, we must default to a return value when a return statement is either omitted or never reached, within a function.

Type casting restrictions

I suggest that we allow conversion between bool <-> char <-> int <-> double and a' pointer <-> b' pointer but not between pointers and "arithmetic" types.

writeString from stdio.h doesn't compile

./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: ✗

Non existing included file handling.

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.

Include bug

When a file includes itself, do not reinclude it.

Fix lambda lifting

Fix the newer lambda lifting implementation on the cg_testing branch.

Call to llc

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.

Deletion checks in semantic analysis

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?

AST Modification

Note to myself to remember to remove the flag --infer from the menhir call in our Makefile, when I actually implement the AST.

Return in middle of a basic block

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.

The lexer does not return the lexeme for EOF

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.

Ref & deref behaviour

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 :) )

Producing the assembly

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.

Testcases Discussion

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.)
  • #61
  • 160-qsort.eds:
    1. We've assumed that we cannot compare characters, with the way we've interpreted the language specification. This is not the main issue. (Changed nothing.)
    2. The problem is that the functions 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.)

Semantic Analysis Issues

  • In assignments, we must check whether or not the LHS is an l-value.
  • Make sure that NULL can be assigned to a pointer of any type.
  • Handle exceptions wherever needed.
  • Support function overload (in add_definition & add_declaration) or scrap this feature completely.
    Function overloading example: (Do not allow such a case)
#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;
}
  • Implement semantic analysis for function calls. (Strongly correlated with the issue above)
      Things to pay attention to:
        1. Check existence of function
        2. Check that the provided values match the parameters (Check that we provide mutable values to byref parameters)
  • Currently cannot have two parameters with the same name, like in the following example:
int trunc (double d);
int round (double d); 
  • Function Shadowing
  • Weird Shadowing:
main(){
     fun1(){
          fdef(){}
          fdef();
    }

      fun2(){
          fdef(){ fun1(); }
      }
}
  • Currently, when we declare a function and redeclare it or define it, the parameter names must be the same.
  • Currently, we cannot declare a function after we've defined it, which seems weird for the program to fail.
  • Should we allow overloading of the main function as well as shadowing?
  • We should not allow the user to refer to something that is not "stored" in memory, a non l-value.

Problematic return of `NULL` value

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.

Decide the building process

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?

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.