From 5267c0e8653b431cfd2c06212cdba4f22225bd02 Mon Sep 17 00:00:00 2001 From: Mel Date: Thu, 21 Apr 2022 03:18:46 +0200 Subject: Do not force generics for Expr and Stmt --- pkg/lang/ast/ast.go | 4 ++-- pkg/lang/ast/expr.go | 22 ++++++++++++---------- pkg/lang/ast/nodes.go | 5 +++-- pkg/lang/ast/stmt.go | 19 ++++++++++++------- 4 files changed, 29 insertions(+), 21 deletions(-) (limited to 'pkg/lang') diff --git a/pkg/lang/ast/ast.go b/pkg/lang/ast/ast.go index 43d0c28..4171801 100644 --- a/pkg/lang/ast/ast.go +++ b/pkg/lang/ast/ast.go @@ -1,5 +1,5 @@ package ast type Program struct { - Stmts []Stmt[any] -} \ No newline at end of file + Stmts []Stmt +} diff --git a/pkg/lang/ast/expr.go b/pkg/lang/ast/expr.go index a4d6f56..ab6578a 100644 --- a/pkg/lang/ast/expr.go +++ b/pkg/lang/ast/expr.go @@ -22,35 +22,37 @@ const ( ExprKindThis ) -type Expr[T any] struct { +type Expr ExprT[any] + +type ExprT[T any] struct { At token.Loc Kind ExprKind Value T } type ExprBinary struct { - Left Expr[any] + Left Expr Op BinOp - Right Expr[any] + Right Expr } type ExprUnary struct { Op UnOp - Value Expr[any] + Value Expr } type ExprCall struct { - Callee Expr[any] - Args []Expr[any] + Callee Expr + Args []Expr } type ExprSubscription struct { - Obj Expr[any] - Key Expr[any] + Obj Expr + Key Expr } type ExprGroup struct { - Value Expr[any] + Value Expr } type ExprFnLit struct { @@ -59,7 +61,7 @@ type ExprFnLit struct { } type ExprArrayLit struct { - Values []Expr[any] + Values []Expr } type ExprIdent struct { diff --git a/pkg/lang/ast/nodes.go b/pkg/lang/ast/nodes.go index 699d025..55dbb5b 100644 --- a/pkg/lang/ast/nodes.go +++ b/pkg/lang/ast/nodes.go @@ -9,10 +9,11 @@ type IdentNode struct { type BlockNode struct { At token.Loc - Stmts []Stmt[any] + Stmts []Stmt } type CondNode struct { - Cond Expr[any] + At token.Loc + Cond Expr Then BlockNode } diff --git a/pkg/lang/ast/stmt.go b/pkg/lang/ast/stmt.go index e924f8c..4f24cc5 100644 --- a/pkg/lang/ast/stmt.go +++ b/pkg/lang/ast/stmt.go @@ -5,7 +5,8 @@ import "jinx/pkg/lang/scanner/token" type StmtKind int const ( - StmtKindUse StmtKind = iota + StmtKindEmpty StmtKind = iota + StmtKindUse StmtKindFnDecl StmtKindObjectDecl StmtKindVarDecl @@ -18,7 +19,9 @@ const ( StmtKindExpr ) -type Stmt[T any] struct { +type Stmt StmtT[any] + +type StmtT[T any] struct { At token.Loc Kind StmtKind Value T @@ -40,11 +43,11 @@ type StmtObjectDecl struct{} type StmtVarDecl struct { Name IdentNode - Value Expr[any] + Value Expr } type StmtIf struct { - Cond Expr[any] + Cond Expr Then BlockNode Elifs []CondNode Else BlockNode @@ -58,7 +61,7 @@ type StmtTry struct { } type StmtReturn struct { - Value Expr[any] + Value Expr } type StmtContinue struct{} @@ -66,9 +69,11 @@ type StmtContinue struct{} type StmtBreak struct{} type StmtThrow struct { - Value Expr[any] + Value Expr } type StmtExpr struct { - Value Expr[any] + Value Expr } + +type StmtEmpty struct{} -- cgit 1.4.1