Skip to content

Commit

Permalink
fix bugs oop
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Aug 19, 2024
1 parent ba117ae commit cc8c04f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,18 +445,23 @@ func (interp *interpreter) evaluate(expr parser.Expression) Value {
return &userFunction{"", e.Parameters, e.Ellipsis, e.Body, closure}
case *parser.SemiTag:
return nil
case *parser.MethodCall:
// Evaluate the object and method name
print("Method call: ", e.Method)
return nil

case *parser.NewExpression:
// Evaluate the class name and arguments
className := e.ClassName
print("New exp: Class name: ", className)
//print("New exp: Class name: ", className)
//args := make([]Value, len(e.Args))
//for i, arg := range e.Args {
// args[i] = interp.evaluate(arg)
//}
//
//// Create a new instance of the class
instance := interp.newInstance(className, nil)
print("New exp: Instance: ", instance)
//print("New exp: Instance: ", instance)
return instance
default:
// Parser should never give us this
Expand Down Expand Up @@ -616,7 +621,7 @@ func (interp *interpreter) executeStatement(s parser.Statement) {
// Handle the class definition here
// Create a new class and register it in the environment
className := s.Name
print(className)
//print(className)
//methods := s.Methods // Assuming s.Methods holds the class methods
//// Create a new class object or structure to store the class details
class := &userClass{
Expand Down
3 changes: 2 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,9 @@ func (p *parser) primary() Expression {
}
className := p.val
p.expect(NAME)
args, _ := p.params()

return &NewExpression{pos, className, nil}
return &NewExpression{pos, className, args}
case OBJECT_OPERATOR:
pos := p.pos
p.next() // Move past the OBJECT_OPERATOR token
Expand Down

0 comments on commit cc8c04f

Please sign in to comment.