Files
five/hbrtl/bitops.go
Charles KWON OhJun 59568f3301 Five v0.9 — Harbour + Go fusion language
- Compiler: PP → Lexer → Parser → Analyzer → Gengo pipeline
- Parser: 232/236 (98%) Harbour compatibility, registry-based dispatch
- RTL: 351 Harbour-compatible functions
- RDD: DBF/NTX/CDX engines with Rushmore bitmap optimization
- Go Interop: IMPORT + pkg.Func() + obj:Method() with FastPath (15M calls/sec)
- HB_FUNC API: Full Harbour C API compatible Go bridge
- Concurrency: SPAWN/LAUNCH/GOROUTINE, <-, WATCH, PARALLEL FOR, ASYNC/AWAIT
- Extensions: Multi-return, DEFER, Slice, f-string, Nil-safe ?:, CONST
- Macro Compiler: Runtime AST parsing and evaluation
- Debugger: TUI debugger with source display, breakpoints, stepping
- FRB: Native + Pcode dual mode runtime binary
- Tests: 13 packages ALL PASS

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 09:41:50 +09:00

95 lines
2.1 KiB
Go

// Copyright (c) 2026 Charles KWON OhJun (charleskwonohjun@gmail.com)
// All rights reserved.
// Bit operation functions using Go's native operators.
// HB_BITAND, HB_BITOR, HB_BITXOR, HB_BITSHIFT, HB_BITNOT,
// HB_BITTEST, HB_BITSET, HB_BITRESET
package hbrtl
import "five/hbrt"
// HB_BITAND(nVal1, nVal2 [, nValN...]) → nResult
func HbBitAnd(t *hbrt.Thread) {
nParams := t.ParamCount()
t.Frame(nParams, 0)
defer t.EndProc()
result := t.Local(1).AsLong()
for i := 2; i <= nParams; i++ {
result &= t.Local(i).AsLong()
}
t.RetLong(result)
}
// HB_BITOR(nVal1, nVal2 [, nValN...]) → nResult
func HbBitOr(t *hbrt.Thread) {
nParams := t.ParamCount()
t.Frame(nParams, 0)
defer t.EndProc()
result := t.Local(1).AsLong()
for i := 2; i <= nParams; i++ {
result |= t.Local(i).AsLong()
}
t.RetLong(result)
}
// HB_BITXOR(nVal1, nVal2 [, nValN...]) → nResult
func HbBitXor(t *hbrt.Thread) {
nParams := t.ParamCount()
t.Frame(nParams, 0)
defer t.EndProc()
result := t.Local(1).AsLong()
for i := 2; i <= nParams; i++ {
result ^= t.Local(i).AsLong()
}
t.RetLong(result)
}
// HB_BITNOT(nVal) → nResult
func HbBitNot(t *hbrt.Thread) {
t.Frame(1, 0)
defer t.EndProc()
t.RetLong(^t.Local(1).AsLong())
}
// HB_BITSHIFT(nVal, nShift) → nResult
// nShift > 0: left shift, nShift < 0: right shift
func HbBitShift(t *hbrt.Thread) {
t.Frame(2, 0)
defer t.EndProc()
val := t.Local(1).AsLong()
shift := t.Local(2).AsLong()
if shift >= 0 {
t.RetLong(val << uint(shift))
} else {
t.RetLong(val >> uint(-shift))
}
}
// HB_BITTEST(nVal, nBit) → lSet
func HbBitTest(t *hbrt.Thread) {
t.Frame(2, 0)
defer t.EndProc()
val := t.Local(1).AsLong()
bit := uint(t.Local(2).AsLong())
t.RetBool((val & (1 << bit)) != 0)
}
// HB_BITSET(nVal, nBit) → nResult
func HbBitSet(t *hbrt.Thread) {
t.Frame(2, 0)
defer t.EndProc()
val := t.Local(1).AsLong()
bit := uint(t.Local(2).AsLong())
t.RetLong(val | (1 << bit))
}
// HB_BITRESET(nVal, nBit) → nResult
func HbBitReset(t *hbrt.Thread) {
t.Frame(2, 0)
defer t.EndProc()
val := t.Local(1).AsLong()
bit := uint(t.Local(2).AsLong())
t.RetLong(val &^ (1 << bit))
}