-
Notifications
You must be signed in to change notification settings - Fork 19
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
base: develop
Are you sure you want to change the base?
Conversation
0a19770
to
2744225
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- How about changing function from ScopingXXX to ResolveXXX, later these functions should do type checking.
- How about changing Symbol to Object?
symbol/scope.go
Outdated
} | ||
// Define scope errors | ||
type DupError struct { | ||
Identifier ast.Identifier |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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: | ||
{ |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are all WIP..:-)
13d2a62
to
97a9e19
Compare
} | ||
|
||
func (s *Scope) Get(name string) Object { | ||
scope := s |
There was a problem hiding this comment.
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
??
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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!
97a9e19
to
8639abd
Compare
8639abd
to
69a9ce2
Compare
caac93f
to
8ec4c1a
Compare
[WIP] Refactoring scope