wrote dsl for ast boiler plate generation

This commit is contained in:
basil 2025-06-08 21:18:17 -04:00
parent b244f7e3b2
commit e0dd8ff9d5
Signed by: basil
SSH key fingerprint: SHA256:y04xIFL/yqNaG9ae9Vl95vELtHfApGAIoOGLeVLP/fE
16 changed files with 915 additions and 60 deletions

View file

@ -36,7 +36,7 @@ func (i *Interpreter) VisitBinaryExpr(b *ast.BinaryExpr) any {
areStrings := leftType == LoxTypeString &&
rightType == LoxTypeString
switch b.Operator.Type {
switch b.Op.Type {
case lexer.TokenTypeMinus:
if !areNumbers {
// todo: error here
@ -119,7 +119,7 @@ func (i *Interpreter) VisitLiteralExpr(g *ast.LiteralExpr) any {
func (i *Interpreter) VisitUnaryExpr(g *ast.UnaryExpr) any {
right := i.Evaluate(g.Right)
switch g.Operator.Type {
switch g.Op.Type {
case lexer.TokenTypeMinus:
if right.Type() != LoxTypeNumber {
// todo: error here

27
runtime/loxtype_string.go Normal file
View file

@ -0,0 +1,27 @@
// Code generated by "stringer -type LoxType -trimprefix LoxType"; DO NOT EDIT.
package runtime
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[LoxTypeString-0]
_ = x[LoxTypeNumber-1]
_ = x[LoxTypeBoolean-2]
_ = x[LoxTypeNil-3]
_ = x[LoxTypeUndefined-4]
}
const _LoxType_name = "StringNumberBooleanNilUndefined"
var _LoxType_index = [...]uint8{0, 6, 12, 19, 22, 31}
func (i LoxType) String() string {
if i < 0 || i >= LoxType(len(_LoxType_index)-1) {
return "LoxType(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _LoxType_name[_LoxType_index[i]:_LoxType_index[i+1]]
}