restructure
This commit is contained in:
parent
edcbfde351
commit
eebaadc16e
21 changed files with 937 additions and 626 deletions
31
runtime/interpreter.go
Normal file
31
runtime/interpreter.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package runtime
|
||||
|
||||
import "git.red-panda.pet/pandaware/lox-go/ast"
|
||||
|
||||
type Interpreter struct{}
|
||||
|
||||
var _ ast.ExprVisitor = new(Interpreter)
|
||||
|
||||
func NewInterpreter() *Interpreter {
|
||||
return new(Interpreter)
|
||||
}
|
||||
|
||||
// VisitBinaryExpr implements ast.ExprVisitor.
|
||||
func (i *Interpreter) VisitBinaryExpr(b *ast.BinaryExpr) any {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// VisitGroupingExpr implements ast.ExprVisitor.
|
||||
func (i *Interpreter) VisitGroupingExpr(g *ast.GroupingExpr) any {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// VisitLiteralExpr implements ast.ExprVisitor.
|
||||
func (i *Interpreter) VisitLiteralExpr(g *ast.LiteralExpr) any {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// VisitUnaryExpr implements ast.ExprVisitor.
|
||||
func (i *Interpreter) VisitUnaryExpr(g *ast.UnaryExpr) any {
|
||||
panic("unimplemented")
|
||||
}
|
||||
33
runtime/types.go
Normal file
33
runtime/types.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package runtime
|
||||
|
||||
//go:generate stringer -type LoxType -trimprefix LoxType
|
||||
type LoxType int
|
||||
|
||||
const (
|
||||
LoxTypeString LoxType = iota
|
||||
LoxTypeNumber
|
||||
LoxTypeBoolean
|
||||
LoxTypeNil
|
||||
LoxTypeUndefined
|
||||
)
|
||||
|
||||
type LoxValue struct {
|
||||
raw any
|
||||
}
|
||||
|
||||
func (v *LoxValue) Type() LoxType {
|
||||
switch v.raw.(type) {
|
||||
case string:
|
||||
return LoxTypeString
|
||||
case float64, float32:
|
||||
return LoxTypeNumber
|
||||
case bool:
|
||||
return LoxTypeBoolean
|
||||
default:
|
||||
return LoxTypeUndefined
|
||||
}
|
||||
}
|
||||
|
||||
func Value(v any) *LoxValue {
|
||||
return &LoxValue{v}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue