-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix method calls * Add support for class properties
- Loading branch information
Showing
11 changed files
with
166 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ast | ||
|
||
import "github.com/sevenreup/duwa/src/token" | ||
|
||
type PropertyExpression struct { | ||
Token token.Token | ||
Left Expression | ||
Property Expression | ||
} | ||
|
||
func (pe *PropertyExpression) expressionNode() {} | ||
|
||
func (pe *PropertyExpression) TokenLiteral() string { return pe.Token.Literal } | ||
|
||
func (pe *PropertyExpression) String() string { | ||
return pe.Left.String() + "." + pe.Property.String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package evaluator | ||
|
||
import ( | ||
"github.com/sevenreup/duwa/src/ast" | ||
"github.com/sevenreup/duwa/src/object" | ||
"github.com/sevenreup/duwa/src/values" | ||
) | ||
|
||
func evaluateProperty(node *ast.PropertyExpression, env *object.Environment) object.Object { | ||
left := Eval(node.Left, env) | ||
|
||
if isError(left) { | ||
return left | ||
} | ||
|
||
switch receiver := left.(type) { | ||
case *object.Instance: | ||
return evaluateInstanceProperty(node, receiver) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func evaluateInstanceProperty(node *ast.PropertyExpression, instance *object.Instance) object.Object { | ||
property := node.Property.(*ast.Identifier) | ||
|
||
if instance.Env.Has(property.Value) { | ||
val, _ := instance.Env.Get(property.Value) | ||
return val | ||
} | ||
|
||
if instance.Class.Env.Has(property.Value) { | ||
val, _ := instance.Class.Env.Get(property.Value) | ||
return val | ||
} | ||
|
||
// If the property is not found in the instance or the class, return NULL | ||
instance.Env.Set(property.Value, values.NULL) | ||
return values.NULL | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters