Code Monkey home page Code Monkey logo

compilers-ntua's People

Contributors

jimv4 avatar urcodeboijorto574 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jimv4

compilers-ntua's Issues

Functions can't be called if they're not defined in their parent function's scope.

A function that is not defined/declared in the local definitions of a function can't be called in its block. This happens because each function is accompanied with a stack frame pointer which, in this case, is not set correctly. An error message for this occasion is shown below:

llc: error: llc: a.ll:131:13: error: '@a' defined with type 'void (%frame_main*, i64)*' but expected 'void (%frame_cirr*, i64)*'
  call void @a(%frame_cirr* %stack_frame_cirr, i64 0)

In the example above, 'a' and 'cirr' functions are defined in the local definitions of 'main' function and in the block of 'cirr' function 'a' is called. So, a search happens for 'a' function using the stack frame pointer that points to 'cirr' and the search fails.

Escape character \n does not work

writeString("Hello World!!!\n.This is my first grace program.").
This line should print two lines, however only one is printed. Perhaps we should check the lexer.

Lvalues have no semantics

Currenlty lvalues have not semantics behind them, they are just ids, so when we want to gen an lvalue address we do not know if this lvalue is a variable reference. One solution would be to change the Ast and the Parser but it will need a refactor. Temp solution is to add a third field to variables records of each function, holding if the variable is a reference (pointer) or not.

Error messages are too generic!

Currently, the error messages the the compiler prints are very generic.
Each error message should include the following information:

  • Type of error: lectic, syntactic or semantic error
  • Line and column number
  • Detailed Message so that the way the error is fixed is graspable.

Problem when running sierpinski.grc

llc: error: llc: a.ll:412:3: error: instruction expected to be numbered '%4'
%3 = call i64 @iPow(%frame_triangle* %access_link_ptr9, i64 %x6, i64 %subtmp)

We cannot have in the else branch both ret and br statements. We must have only one and at the end.
Line 415: ret i64 %multmp
br label %if_then_else_cont

Here we must have only one of these

Problem on if-then-else when running primes.grc

llc: error: llc: a.ll:205:7: error: value doesn't match function result type 'i64'
ret void
^
clang: error: no such file or directory: 'a.s'

If i put ret i64 0, the program works as expected

Optimizations don't work due to this (probably)

When haveing a ret statement followed by a branch statement in if-then-else and while, we get this error from llvm:

Terminator found in the middle of a basic block!
label %while

This causes the optimizations to be corrupted and not working as expected.

A variable declared in an ancestor scope that isn't the immediate parent can't be accessed.

The following example results in an infinite loop when in generation of IR:

fun main() : nothing
  var errorValue : int;
  fun sum(x, y : int) : int
    fun incrByStep(a, step : int) : int {
      if 1 < 0 then return errorValue;
      else          return a + step;
    }
  { return incrByStep(x, y); }

{
  errorValue <- -1;
  writeString("1 + 2 = ");
  writeInteger(sum(1, 2));
  writeChar('\n');
}

Note: the infinite loop happened when encountered the lvalue 'errorValue' in line 5.

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.