Skip to content

Commit 2bb1d47

Browse files
committed
Move value.go into vm/
1 parent 101ac41 commit 2bb1d47

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

compiler/codegen/generator.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2726
type CodeGenerator struct {
@@ -54,16 +53,13 @@ func (cg *CodeGenerator) Run() compiler.PhaseStatus {
5453

5554
func (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) {
9995
func (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:

vm/bytecode.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
package vm
1616

17-
import "github.com/RohitAwate/commaql/vm/types"
18-
1917
type OpCode uint
2018

2119
const (
@@ -71,17 +69,17 @@ func GetOpCodeInfo(opCode OpCode) OpCodeInfo {
7169

7270
type Bytecode struct {
7371
Blob []OpCode
74-
ConstantsPool []types.Value
72+
ConstantsPool []Value
7573
}
7674

7775
func NewBytecode() Bytecode {
7876
return Bytecode{
7977
Blob: []OpCode{},
80-
ConstantsPool: []types.Value{},
78+
ConstantsPool: []Value{},
8179
}
8280
}
8381

84-
func (b *Bytecode) AddConstant(v types.Value) uint {
82+
func (b *Bytecode) AddConstant(v Value) uint {
8583
b.ConstantsPool = append(b.ConstantsPool, v)
8684
return uint(len(b.ConstantsPool) - 1)
8785
}

vm/types/value.go renamed to vm/value.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package types
15+
package vm
1616

1717
import (
1818
"fmt"

0 commit comments

Comments
 (0)