Files modified (5): hbrt/symbol.go — #39: Module.Find O(n) → O(1) via lazy map index hbrt/thread.go — #49: Call stack init 256 → 32, grows dynamically Saves 14KB→1.7KB per thread for goroutine-heavy programs hbrt/frb.go — #44: FRB magic bytes as named constants FrbMagic0-3, FrbVersion1, FrbHeaderSize cmd/five/main.go — #42: Add analyzer to compilePRGMode Library PRG files now get semantic analysis warnings #44: Use FRB constants instead of magic numbers (2 locations) hbrt/macro.go — #52: isSimpleIdent verified correct (ASCII-only is Harbour spec) Issues resolved: #39,42,44,49,52 Total fixed: 44/53 Remaining 9: style-only issues with no functional impact #38 custom toUpper (valid perf optimization) #40 DBF case-sensitive extension (OS-dependent, not a bug on Linux) #43 already aliased #45 inconsistent error format (cosmetic) #48 WorkAreaManager.Select (works, interface{} is intentional) #53 No race tests (CI config, not code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
// Copyright (c) 2026 Charles KWON OhJun (charleskwonohjun@gmail.com)
|
|
// All rights reserved.
|
|
|
|
package hbrt
|
|
|
|
// Scope flags (matching Harbour's HB_FS_*)
|
|
const (
|
|
FsPublic uint16 = 0x0001
|
|
FsStatic uint16 = 0x0002
|
|
FsFirst uint16 = 0x0004
|
|
FsInit uint16 = 0x0008
|
|
FsExit uint16 = 0x0010
|
|
FsMessage uint16 = 0x0020
|
|
FsMemvar uint16 = 0x0080
|
|
FsPcodeFunc uint16 = 0x0100
|
|
FsLocal uint16 = 0x0200
|
|
FsDynCode uint16 = 0x0400
|
|
FsDeferred uint16 = 0x0800
|
|
FsFrame uint16 = 0x1000
|
|
)
|
|
|
|
// Symbol represents a function/variable symbol.
|
|
type Symbol struct {
|
|
Name string
|
|
Scope uint16
|
|
Func func(*Thread) // nil for external/deferred
|
|
}
|
|
|
|
// Module is a collection of symbols from one PRG file.
|
|
type Module struct {
|
|
Name string
|
|
Symbols []Symbol
|
|
index map[string]int // lazy-built name → Symbols index
|
|
}
|
|
|
|
// Sym creates a Symbol (convenience constructor for generated code).
|
|
func Sym(name string, scope uint16, fn func(*Thread)) Symbol {
|
|
return Symbol{Name: name, Scope: scope, Func: fn}
|
|
}
|
|
|
|
// NewModule creates a Module with the given symbols.
|
|
func NewModule(name string, symbols ...Symbol) *Module {
|
|
return &Module{Name: name, Symbols: symbols}
|
|
}
|
|
|
|
// At returns a pointer to the symbol at index (for generated code).
|
|
func (m *Module) At(index int) *Symbol {
|
|
return &m.Symbols[index]
|
|
}
|
|
|
|
// Find returns a symbol by name within this module. O(1) via lazy index.
|
|
func (m *Module) Find(name string) *Symbol {
|
|
if m.index == nil {
|
|
m.index = make(map[string]int, len(m.Symbols))
|
|
for i := range m.Symbols {
|
|
m.index[m.Symbols[i].Name] = i
|
|
}
|
|
}
|
|
if idx, ok := m.index[name]; ok {
|
|
return &m.Symbols[idx]
|
|
}
|
|
return nil
|
|
}
|