-
Notifications
You must be signed in to change notification settings - Fork 0
Add dynamic schema table lookup via generated instructions #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package instructions | ||
|
|
||
| import ( | ||
| "github/com/lucasbn/sqlite-clone/app/machine/common" | ||
| "github/com/lucasbn/sqlite-clone/app/machine/state" | ||
| ) | ||
|
|
||
| type Goto[T any] struct { | ||
| JumpAddress uint64 | ||
| } | ||
|
|
||
| var _ Instruction[any] = Goto[any]{} | ||
|
|
||
| func (g Goto[T]) Execute(s *state.MachineState[T], b common.BTreeEngine[T]) [][]T { | ||
| s.CurrentAddress = int(g.JumpAddress) | ||
| return [][]T{} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package instructions | ||
|
|
||
| import ( | ||
| "github/com/lucasbn/sqlite-clone/app/machine/common" | ||
| "github/com/lucasbn/sqlite-clone/app/machine/state" | ||
| "github/com/lucasbn/sqlite-clone/app/types" | ||
| ) | ||
|
|
||
| type Ne[T any] struct { | ||
| Register1 int | ||
| Register2 int | ||
| JumpAddress uint64 | ||
| } | ||
|
|
||
| var _ Instruction[any] = Ne[any]{} | ||
|
|
||
| func (ne Ne[T]) Execute(s *state.MachineState[T], b common.BTreeEngine[T]) [][]T { | ||
| val1 := s.Registers.Get(ne.Register1) | ||
| val2 := s.Registers.Get(ne.Register2) | ||
|
|
||
| equal := compareValues(val1, val2) | ||
|
|
||
| if !equal { | ||
| s.CurrentAddress = int(ne.JumpAddress) | ||
| } else { | ||
| s.CurrentAddress++ | ||
| } | ||
|
|
||
| return [][]T{} | ||
| } | ||
|
|
||
| // compareValues compares two values for equality. It handles the specific | ||
| // Entry types used by this SQLite clone. | ||
| func compareValues[T any](a, b T) bool { | ||
| // Type assert to Entry interface and compare based on type | ||
| aEntry, aOk := any(a).(types.Entry) | ||
| bEntry, bOk := any(b).(types.Entry) | ||
|
|
||
| if !aOk || !bOk { | ||
| return false | ||
| } | ||
|
|
||
| switch aVal := aEntry.(type) { | ||
| case types.TextEntry: | ||
| if bVal, ok := bEntry.(types.TextEntry); ok { | ||
| return aVal.Value == bVal.Value | ||
| } | ||
| case types.NumberEntry: | ||
| if bVal, ok := bEntry.(types.NumberEntry); ok { | ||
| return aVal.Value == bVal.Value | ||
| } | ||
| case types.NullEntry: | ||
| _, ok := bEntry.(types.NullEntry) | ||
| return ok | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
Comment on lines
+32
to
+58
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package instructions | ||
|
|
||
| import ( | ||
| "github/com/lucasbn/sqlite-clone/app/machine/common" | ||
| "github/com/lucasbn/sqlite-clone/app/machine/state" | ||
| "github/com/lucasbn/sqlite-clone/app/types" | ||
| ) | ||
|
|
||
| type OpenReadFromRegister[T any] struct { | ||
| CursorID uint64 | ||
| PageRegister int | ||
| } | ||
|
|
||
| var _ Instruction[any] = OpenReadFromRegister[any]{} | ||
|
|
||
| func (o OpenReadFromRegister[T]) Execute(s *state.MachineState[T], b common.BTreeEngine[T]) [][]T { | ||
| s.CurrentAddress++ | ||
|
|
||
| // Get the root page number from the register | ||
| regValue := s.Registers.Get(o.PageRegister) | ||
|
|
||
| // Type assert to extract the int64 value from NumberEntry | ||
| entry, ok := any(regValue).(types.Entry) | ||
| if !ok { | ||
| panic("OpenReadFromRegister: register value is not an Entry") | ||
| } | ||
|
|
||
| numEntry, ok := entry.(types.NumberEntry) | ||
| if !ok { | ||
| panic("OpenReadFromRegister: register value is not a NumberEntry") | ||
| } | ||
|
|
||
| rootPage := uint64(numEntry.Value) | ||
lucasbn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| b.NewCursor(o.CursorID, rootPage) | ||
|
|
||
| return [][]T{} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package instructions | ||
|
|
||
| import ( | ||
| "github/com/lucasbn/sqlite-clone/app/machine/common" | ||
| "github/com/lucasbn/sqlite-clone/app/machine/state" | ||
| ) | ||
|
|
||
| type String[T any] struct { | ||
| Register int | ||
| Value T | ||
| } | ||
|
|
||
| var _ Instruction[int] = String[int]{} | ||
|
|
||
| func (str String[T]) Execute(s *state.MachineState[T], b common.BTreeEngine[T]) [][]T { | ||
| s.CurrentAddress++ | ||
|
|
||
| s.Registers = s.Registers.Set(str.Register, str.Value) | ||
| return [][]T{} | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.