Implements skel functions for scope refactoring#358
Implements skel functions for scope refactoring#358boohyunsik wants to merge 5 commits intoDE-labtory:developfrom
Conversation
0a19770 to
2744225
Compare
zeroFruit
left a comment
There was a problem hiding this comment.
- How about changing function from ScopingXXX to ResolveXXX, later these functions should do type checking.
- How about changing Symbol to Object?
| } | ||
| // Define scope errors | ||
| type DupError struct { | ||
| Identifier ast.Identifier |
There was a problem hiding this comment.
I think it is better DupError has Symbol not Identifier
| s = NewEnclosedScope(s) | ||
|
|
||
| if err := ScopingFunctionParameter(f.Parameters, s); err != nil { | ||
| return nil |
|
|
||
| func (s *Scope) GetOuter() *Scope { | ||
| return s.outer | ||
| func ScopingFunctionParameter(f []*ast.ParameterLiteral, s *Scope) error { |
There was a problem hiding this comment.
why f ? could have better name
| for _, p := range f { | ||
| switch p.Type { | ||
| case ast.IntType: | ||
| { |
| err = ScopingIfStatement(implStmt, scope) | ||
| } | ||
|
|
||
| if err != nil { |
There was a problem hiding this comment.
I think this if statement don't need, just return err enough
| func NewScope() *Scope { | ||
| return &Scope{ | ||
| store: make(map[string]Symbol), | ||
| parent: nil, |
There was a problem hiding this comment.
These are all WIP..:-)
13d2a62 to
97a9e19
Compare
| } | ||
|
|
||
| func (s *Scope) Get(name string) Object { | ||
| scope := s |
There was a problem hiding this comment.
Why use scope variable instead of s??
There was a problem hiding this comment.
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 |
|
|
||
| var obj Object | ||
| var t ObjectType | ||
| switch p.Type { |
There was a problem hiding this comment.
(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| } | ||
|
|
||
| func ResolveFunctionParameter(p []*ast.ParameterLiteral, r *Resolver) error { | ||
| for _, p := range p { |
There was a problem hiding this comment.
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.
case *ast.AssignStatement:
return ResolveAssignStatement(implStmt, r)is better!
97a9e19 to
8639abd
Compare
8639abd to
69a9ce2
Compare
caac93f to
8ec4c1a
Compare
[WIP] Refactoring scope