mewmew / uc

A compiler for the µC language.
58 stars 5 forks source link

semantic: Cleanup and separation of concern #57

Closed mewmew closed 8 years ago

mewmew commented 8 years ago

The semantic analysis and type-checker packages are in need of love and could use a refactoring to clear up their separation of concern. Currently semcheck.Check is empty, and typecheck.Check does all the work, even pure semantic-checking. We should separate concern and clean up this part of the code.

sangisos commented 8 years ago

I agree. Was trying to separate things, but didn't separate enough. Let's go through this tomorrow.

Med Vänliga Hälsningar Alexander Andersson On 29 Apr 2016 02:16, "Robin Eklind" notifications@github.com wrote:

The semantic analysis and type-checker packages are in need of love and could use a refactoring to clear up their separation of concern. Currently semcheck.Check is empty, and typecheck.Check does all the work, even pure semantic-checking. We should separate concern and clean up this part of the code.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/mewmew/uc/issues/57

mewmew commented 8 years ago

When we do the cleanup (which may happen after v0.3) we should definitely address the issue of resolving identifiers of the universe scope. A temporary workaround was added with commit 12c9719a4ab781d7d315e3f0b5716d34609d1270.

sangisos commented 8 years ago

In the assignment it says

"Hints

You need to design data structures for the representation of the types of variables and functions."

Can we say this is fulfilled with the code in current state?

mewmew commented 8 years ago

Can we say this is fulfilled with the code in current state?

Definitely, it is what the types package does, through the following structure definitions.

// A Basic represents a basic type.
//
// Examples.
//
//    char
//    int
type Basic struct {
    // Kind of basic type.
    Kind BasicKind
}

// An Array represents an array type.
//
// Examples.
//
//    int[]
//    char[128]
type Array struct {
    // Element type.
    Elem Type
    // Array length.
    Len int
}

// A Func represents a function signature.
//
// Examples.
//
//    int(void)
//    int(int a, int b)
type Func struct {
    // Return type.
    Result Type
    // Function parameter types; or nil if void parameter.
    Params []*Field
}
mewmew commented 8 years ago

Initial cleanup in commit 25e4a3cf7a6a7fcd2b20181ddaa8c63b26ea1a7e. The few semantic checks which are still done by the type-checker will remain, as they improve error output. TODOs for pure semantic checks have been moved to the semcheck package.