Skip to content

Commit

Permalink
Implemented nested loops
Browse files Browse the repository at this point in the history
  • Loading branch information
ziflex committed Nov 2, 2024
1 parent 03167dc commit 7b2a607
Show file tree
Hide file tree
Showing 11 changed files with 380 additions and 454 deletions.
4 changes: 2 additions & 2 deletions pkg/compiler/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (
func NewRegisterAllocator() *RegisterAllocator {
return &RegisterAllocator{
registers: make(map[runtime.Operand]*RegisterStatus),
nextRegister: runtime.ResultOperand + 1, // we start at 1 to avoid ResultOperand
nextRegister: runtime.NoopOperand + 1, // we start at 1 to avoid NoopOperand
lifetimes: make(map[string]*RegisterLifetime),
usageGraph: make(map[runtime.Operand]map[runtime.Operand]bool),
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func (ra *RegisterAllocator) findContiguousRegisters(count int) (runtime.Operand

// First, try to find a contiguous block in existing registers
maxReg := ra.nextRegister
for start := runtime.ResultOperand + 1; start < maxReg; start++ {
for start := runtime.NoopOperand + 1; start < maxReg; start++ {
if ra.isContiguousBlockFree(start, count) {
return start, true
}
Expand Down
12 changes: 9 additions & 3 deletions pkg/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/MontFerret/ferret/pkg/parser"
"github.com/MontFerret/ferret/pkg/runtime"
"github.com/MontFerret/ferret/pkg/stdlib"
goruntime "runtime"
)

type Compiler struct {
Expand Down Expand Up @@ -38,14 +39,19 @@ func (c *Compiler) Compile(query string) (program *runtime.Program, err error) {

defer func() {
if r := recover(); r != nil {
buf := make([]byte, 1024)
n := goruntime.Stack(buf, false)
stackTrace := string(buf[:n])

// find out exactly what the error was and set err
// Find out exactly what the error was and set err
switch x := r.(type) {
case string:
err = errors.New(x)
err = errors.New(x + "\n" + stackTrace)
case error:
err = x
err = errors.New(x.Error() + "\n" + stackTrace)
default:
err = errors.New("unknown panic")
err = errors.New("unknown panic\n" + stackTrace)
}

program = nil
Expand Down
Loading

0 comments on commit 7b2a607

Please sign in to comment.