Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements skel functions for scope refactoring #358

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

boohyunsik
Copy link
Collaborator

[WIP] Refactoring scope

@boohyunsik boohyunsik force-pushed the refactor/scope branch 2 times, most recently from 0a19770 to 2744225 Compare February 27, 2019 14:51
Copy link
Member

@zeroFruit zeroFruit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. How about changing function from ScopingXXX to ResolveXXX, later these functions should do type checking.
  2. How about changing Symbol to Object?

symbol/scope.go Outdated
}
// Define scope errors
type DupError struct {
Identifier ast.Identifier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better DupError has Symbol not Identifier

symbol/scope.go Outdated
s = NewEnclosedScope(s)

if err := ScopingFunctionParameter(f.Parameters, s); err != nil {
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return err

symbol/scope.go Outdated
}

func (s *Scope) GetOuter() *Scope {
return s.outer
func ScopingFunctionParameter(f []*ast.ParameterLiteral, s *Scope) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why f ? could have better name

symbol/scope.go Outdated
for _, p := range f {
switch p.Type {
case ast.IntType:
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove {} plz..

symbol/scope.go Outdated
err = ScopingIfStatement(implStmt, scope)
}

if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this if statement don't need, just return err enough

symbol/scope.go Outdated
func NewScope() *Scope {
return &Scope{
store: make(map[string]Symbol),
parent: nil,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need this line

Copy link
Collaborator Author

@boohyunsik boohyunsik Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all WIP..:-)

@boohyunsik boohyunsik force-pushed the refactor/scope branch 7 times, most recently from 13d2a62 to 97a9e19 Compare March 3, 2019 09:07
}

func (s *Scope) Get(name string) Object {
scope := s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use scope variable instead of s??

Copy link
Member

@hihiboss hihiboss Mar 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to clone Scope, scope := *s or func (s Scope) Get(name string) Object {} might be right

r.scope = NewEnclosedScope(r.scope)

if err := ResolveFunctionParameter(f.Parameters, r); err != nil {
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why return nil?


var obj Object
var t ObjectType
switch p.Type {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(refactor)

How about define func resolveParamObj like

func resolveParamObj(p ast.ParameterLiteral) (Object, ObjectType) {
    switch p.Type {
        case ast.IntType:
            return &Integer{Name: p.Identifier}, IntegerObject
    ...
    }

And,

in func ResolveFunctionParameter()

for _, p := range p {
	if obj, ok := r.scope.store[p.Identifier.Name]; ok {
		return DupError{
			object: obj,
		}
	}
	
	obj, t := resolveParamObj(p)
	r.scope.store[p.Identifier.Name] = obj
	r.types[p] = t
	r.defs[p.Identifier] = obj
}
return nil

return nil
}

func ResolveFunctionParameter(p []*ast.ParameterLiteral, r *Resolver) error {
for _, p := range p {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable name is duplicated!
Although there is not any errors, i think it should be changed for readability.
ex) for _, param := params


func ResolveStatement(stmt ast.Statement, r *Resolver) error {
var err error
switch implStmt := stmt.(type) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case *ast.AssignStatement:
		return ResolveAssignStatement(implStmt, r)

is better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants