Skip to content

Implements skel functions for scope refactoring#358

Open
boohyunsik wants to merge 5 commits intoDE-labtory:developfrom
boohyunsik:refactor/scope
Open

Implements skel functions for scope refactoring#358
boohyunsik wants to merge 5 commits intoDE-labtory:developfrom
boohyunsik:refactor/scope

Conversation

@boohyunsik
Copy link
Copy Markdown
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
Copy Markdown
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?

Comment thread symbol/scope.go Outdated
}
// Define scope errors
type DupError struct {
Identifier ast.Identifier
Copy link
Copy Markdown
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

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

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

Choose a reason for hiding this comment

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

return err

Comment thread symbol/scope.go Outdated

func (s *Scope) GetOuter() *Scope {
return s.outer
func ScopingFunctionParameter(f []*ast.ParameterLiteral, s *Scope) error {
Copy link
Copy Markdown
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

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

Choose a reason for hiding this comment

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

remove {} plz..

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

if err != nil {
Copy link
Copy Markdown
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

Comment thread symbol/scope.go Outdated
func NewScope() *Scope {
return &Scope{
store: make(map[string]Symbol),
parent: nil,
Copy link
Copy Markdown
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
Copy Markdown
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
Comment thread symbol/resolver.go
}

func (s *Scope) Get(name string) Object {
scope := s
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread symbol/resolver.go
r.scope = NewEnclosedScope(r.scope)

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

Choose a reason for hiding this comment

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

Why return nil?

Comment thread symbol/resolver.go

var obj Object
var t ObjectType
switch p.Type {
Copy link
Copy Markdown
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

Comment thread symbol/resolver.go
}

func ResolveFunctionParameter(p []*ast.ParameterLiteral, r *Resolver) error {
for _, p := range p {
Copy link
Copy Markdown
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

Comment thread symbol/resolver.go

func ResolveStatement(stmt ast.Statement, r *Resolver) error {
var err error
switch implStmt := stmt.(type) {
Copy link
Copy Markdown
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