@@ -21,7 +21,6 @@ import (
2121 "github.com/RohitAwate/commaql/compiler/ast"
2222 "github.com/RohitAwate/commaql/compiler/parser/tokenizer"
2323 "github.com/RohitAwate/commaql/vm"
24- "github.com/RohitAwate/commaql/vm/types"
2524)
2625
2726type CodeGenerator struct {
@@ -54,16 +53,13 @@ func (cg *CodeGenerator) Run() compiler.PhaseStatus {
5453
5554func (cg * CodeGenerator ) visitSelectStmt (ss * ast.SelectStmt ) {
5655 for _ , tableNode := range ss .Tables {
57- // Add table name to constants pool
58- val := types.String {Meta : tableNode .TableToken .Lexeme }
56+ val := vm.String {Meta : tableNode .TableToken .Lexeme }
5957 loc := cg .Code .AddConstant (val )
6058
61- // Load table name with LOAD_CONST
6259 cg .Code .EmitWithArg (vm .OpLoadConst , loc )
6360 cg .Code .Emit (vm .OpLoadTable )
6461 }
6562
66- // SET_CTX
6763 cg .Code .Emit (vm .OpSetExecCtx )
6864
6965 if ss .WhereClause != nil {
@@ -99,18 +95,18 @@ func (cg *CodeGenerator) visitExpr(expr *ast.Expr) {
9995func (cg * CodeGenerator ) visitLiteral (lit * ast.Literal ) {
10096 switch lit .Meta .Type {
10197 case tokenizer .NUMBER :
102- // TODO: Write a helper for this
103- val := types .NewNumber (lit .Meta .Lexeme )
98+ // TODO: Write a helper for this, lots of duplication between these cases
99+ val := vm .NewNumber (lit .Meta .Lexeme )
104100 loc := cg .Code .AddConstant (val )
105101 cg .Code .EmitWithArg (vm .OpLoadConst , loc )
106102 case tokenizer .TRUE :
107103 fallthrough
108104 case tokenizer .FALSE :
109- val := types .NewBoolean (lit .Meta .Type )
105+ val := vm .NewBoolean (lit .Meta .Type )
110106 loc := cg .Code .AddConstant (val )
111107 cg .Code .EmitWithArg (vm .OpLoadConst , loc )
112108 case tokenizer .STRING :
113- val := types .NewString (lit .Meta .Lexeme )
109+ val := vm .NewString (lit .Meta .Lexeme )
114110 loc := cg .Code .AddConstant (val )
115111 cg .Code .EmitWithArg (vm .OpLoadConst , loc )
116112 default :
0 commit comments