Giter Club home page Giter Club logo

compilation's People

Contributors

matanbt avatar omerk96 avatar shirfrenkel avatar

Watchers

 avatar

compilation's Issues

TYPE Instances - New Design

Currently the following code is considered OK by our code:
int var := 1; var var_name := 1;
That's bc in the second line 'var' is looked for in the SYMBOL_TABLE and is found and we take it as a TYPE int. That's bad.

What we should do? I'll propose a solution in a new branch. Also another think I thought is maybe it'd be a good idea to keep a TYPE_TABLE, in which we should always consult with when deciding that an identifier is a TYPE. Anyway my solution bypasses it for now.

Make sure that we return the correct line

According to what I understand (didn't go to the bottom of it), in get Line we fetch the line of the NEXT token, this of course is not expected behavior.

My suggested solution is to keep track of the previous' token line number.

Classes

AST_CFIELD.java
AST_DEC_CLASS.java

Printing of STRING token

Check if the lexer returns us the string token with quotation marks or not, and fix our printing based on the answer

MIPS implementations

We currently need to implement the MIPS code for the following actions:

  • Array access
  • Array set
  • String equality
  • Field access
  • Field set
  • Function Epilogue
  • Function Prologue
  • Function Return
  • Load - but only for classes
  • Store - but only for classes

Note that I don't think we should do anything in the case of load/store of classes, since we are always working with objects of size 4 (a pointer to the actual class).

Also, need to consider adding PrintString (@ShirFrenkel added the MIPS code for that, but we need to add the IR for it too).

Comments tests

Need to make sure we are passing the following comment tests:

  • Unclosed comments: /* bla bla bla NOT VALID
  • Unclosed comments with invalid tokens: /* bla bla bla < NOT VALID
  • Invalid tokens: /* bla bla bla < */ NOT VALID
  • Multi closing of comments: /* comment */ id */ NOT VALID
  • Comment with something resembling */: /* comment * / */ VALID
  • Should work: /* SA */ < */ VALID

Arrays - New Expression Metadata

Make sure we get the correct size for the array. That means that if it is a constant integral size, just save it, else we should save the AST node containing the element containing the size of the array (for example, the variable holding the size of the array when we create it).

The total size of the array is: (1 + length) * 4, where the 1 stands for a field that holds the length of the array.

Remove duplicate files

When we cloned the HW assignment, we also cloned AST_EXP_VAR_FIELD.java AST_EXP_VAR_SIMPLE.java AST_EXP_VAR_SUBSCRIPT.java, which are the old names of the following files - AST_VAR_FIELD.java AST_VAR_SIMPLE.java AST_VAR_SUBSCRIPT.java.

I didn't remove them yet, because some of the old files still have some useful SemantMe in them.

Classes Metadata

We should create a list containing all the fields of the class. This should support inheritance. The list should be ordered, having the greatest ancestor's fields first.

We can implement it efficiently by creating a JOIN operation in the AST class node, that takes the list of the father, and joins it with the list of immediate fields of the son, while making sure we are ignoring "override" fields, like an int x; field in both father and son, since only the father's should count.

We should create a similar list of (name, function_object), but for methods. This should also support a JOIN operation, but this time we override the values function_object in case of collision.

We can now get the size of the class: (1 + total_fields) * 4, where the 1 stands for the vtable of the class.

Adding our Nodes (hey! that's node funny anymore.)

Just a recap of what I did so we wouldn't do double work + some notes.
Ill edit this comment whenever I have progress:

NOTES - Please Read:

  • AST_EXP and AST_STMT and AST_VAR must be kept, and expression subclasses must inherent from its as well as var subclasses (I am based on this, and I believe you will to).
  • Also I think these abstract-classes should have PrintMe function (didn't get to the bottom of it).

DONE:

  • AST_TYPE for "type"
  • AST_FUNC for "decFunc"
  • AST_FUNC_ARG will be a node for a function argument and will have one child of with its TYPE.
  • AST_FUNC_ARG_LIST is literally a list of AST_FUNC_ARG
  • AST_EXP_LIST same for AST_EXP
  • AST_EXP_BINOP was upgraded
    -AST_NEW_EXP for "newExp", this is intentionally not 'AST_EXP_NEW' because it is not type of expression.

LEFT:

  • I'll be finishing STMTs
  • make PrintMe better, so debugging we'll be easier

Verify: void main()

We should decide how we verify the existence of a void and argument-less global function main().

I see it as an addition to AST_FUNC_DEC semantMe, that will be checked by Main.java.

findScope

change findScopeClass to return TYPE_CLASS (and not AST)
Suggestion: do more general func: findScope (instead of findScopeClass, findScopeFunc), and return there TYPE and not AST

Future Thinking - Properties for CodeGen

  • Each var has an address in the stack during runtime, which is calculated by offset from $FP , That would be a TABLE_ENTRY property, specifically TABLE_ENTRY.stack_offset
  • Each field in a class have its own offset in the object struct, so TYPE_CFIELD.object_offset is required.
  • Each instance-type has a size (in memory) in which it requires (only exception is array-instance, that can be only calculated given the array length). We should define TYPE.size property .
  • Also each table-entry will contain the same information specifically for the var - TABLE_ENTRY.size
  • CF

Assignments

Includes: AST_DEC_VAR, AST_STMT_ASSIGN, AST_STMT_ASSIGN_NEW

Depends on:

  • the static function: TYPE.checkAssignment(left, right), validate assignment of types: left := right and handles error in place.
  • the instance method: TYPE_CLASS.isSubClassOf(potentialFather) - which checks inheretence.
  • the instance method TYPE.isClass() that return true when the type is class.

Functions & Variable Declarations Metadata

Includes:
AST_DEC_FUNC.java
AST_DEC_FUNC_ARG.java
AST_DEC_FUNC_ARG_LIST.java
AST_STMT_ASSIGN.java
AST_STMT_RETURN.java

When calling SemantMe() on the function body, we should run a counter on the number of variable declarations (including inside if and while blocks). That way, we will know how much space to leave for the prelude of the function. We should also save the total number of variable declarations inside the function.

Inside the statement of the variable declaration (and only inside statements, not in global variables), we should save the index of the variable declaration inside the encompassing function.

The total size of the prelude should be: (1 + counter) * 4, where the 1 stands for the RA.

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.