// Copyright (c) 2026 Charles KWON OhJun (charleskwonohjun@gmail.com) // All rights reserved. // RDD-related RTL functions: EOF(), BOF(), Found(), RecNo(), RecCount(), Deleted(). // These read the current workarea state from Thread.WA. package hbrtl import ( "five/hbrt" "five/hbrdd" ) func rtlEOF(t *hbrt.Thread) { t.Frame(0, 0) defer t.EndProc() if wa := getWA(t); wa != nil { if area := wa.Current(); area != nil { t.PushBool(area.EOF()) t.RetValue() return } } t.PushBool(true) t.RetValue() } func rtlBOF(t *hbrt.Thread) { t.Frame(0, 0) defer t.EndProc() if wa := getWA(t); wa != nil { if area := wa.Current(); area != nil { t.PushBool(area.BOF()) t.RetValue() return } } t.PushBool(true) t.RetValue() } func rtlFound(t *hbrt.Thread) { t.Frame(0, 0) defer t.EndProc() if wa := getWA(t); wa != nil { if area := wa.Current(); area != nil { t.PushBool(area.Found()) t.RetValue() return } } t.PushBool(false) t.RetValue() } func rtlRecNo(t *hbrt.Thread) { t.Frame(0, 0) defer t.EndProc() if wa := getWA(t); wa != nil { if area := wa.Current(); area != nil { t.RetInt(int64(area.RecNo())) return } } t.RetInt(0) } func rtlRecCount(t *hbrt.Thread) { t.Frame(0, 0) defer t.EndProc() if wa := getWA(t); wa != nil { if area := wa.Current(); area != nil { rc, _ := area.RecCount() t.RetInt(int64(rc)) return } } t.RetInt(0) } func rtlDeleted(t *hbrt.Thread) { t.Frame(0, 0) defer t.EndProc() if wa := getWA(t); wa != nil { if area := wa.Current(); area != nil { t.PushBool(area.Deleted()) t.RetValue() return } } t.PushBool(false) t.RetValue() } func rtlFieldGet(t *hbrt.Thread) { // FIELD->name is handled by gengo codegen, not this function. // This is for FieldGet(n) function call. t.Frame(1, 0) defer t.EndProc() n := int(t.Local(1).AsNumInt()) if wa := getWA(t); wa != nil { if area := wa.Current(); area != nil { val, err := area.GetValue(n - 1) // 1-based to 0-based if err == nil { t.PushValue(val) t.RetValue() return } } } t.PushNil() t.RetValue() } func getWA(t *hbrt.Thread) *hbrdd.WorkAreaManager { if t.WA == nil { return nil } wa, ok := t.WA.(*hbrdd.WorkAreaManager) if !ok { return nil } return wa }