feat: FiveSql2 43/43, @byref, mutable closure, RTL 479, DateTime fix
Major changes since last commit: - FiveSql2 SQL:1999 engine (10,458 LOC) — 43/43 ALL PASS - 21 compiler/runtime bugs fixed (short-circuit AND/OR, FOR LOOP, etc.) - @byref pass-by-reference via RefCell pattern - Mutable closure capture (EnsureLocalRef + RefCell sharing) - RTL: 400 → 479 functions (+79: file, string, datetime, hash, UTF-8) - DateTime/Timestamp fully working (hb_DateTime, hb_Hour/Min/Sec, display) - Reserved word guard (39 keywords blocked from function calls) - AEval arg order fix (element before index) - Closure capture redecl fix (unique _cap_ names per block) - Hash/string indexing in ArrayPush/ArrayPop - Harbour compat test suite: 51/51 - 4 docs: Porting Report, Implementation Plan, Optimization Plan, Commercialization Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
92
examples/test_byref.prg
Normal file
92
examples/test_byref.prg
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* test_byref.prg — @byref pass-by-reference test
|
||||
*/
|
||||
|
||||
STATIC s_nPass := 0
|
||||
STATIC s_nFail := 0
|
||||
|
||||
PROCEDURE Main()
|
||||
|
||||
? "=== @byref Test Suite ==="
|
||||
?
|
||||
|
||||
TestBasicByref()
|
||||
TestChainedByref()
|
||||
TestByrefInLoop()
|
||||
TestByrefPreservesType()
|
||||
|
||||
?
|
||||
? "Results:", hb_ntos(s_nPass), "/", hb_ntos(s_nPass + s_nFail), "passed"
|
||||
|
||||
RETURN
|
||||
|
||||
|
||||
STATIC PROCEDURE TestBasicByref()
|
||||
LOCAL nVal := 10
|
||||
|
||||
ModifyByRef(@nVal)
|
||||
Assert("Basic @byref: nVal changed to 42", nVal == 42)
|
||||
|
||||
RETURN
|
||||
|
||||
STATIC FUNCTION ModifyByRef(nParam)
|
||||
nParam := 42
|
||||
RETURN NIL
|
||||
|
||||
|
||||
STATIC PROCEDURE TestChainedByref()
|
||||
LOCAL nVal := 100
|
||||
|
||||
MiddleMan(@nVal)
|
||||
Assert("Chained @byref: nVal changed to 999", nVal == 999)
|
||||
|
||||
RETURN
|
||||
|
||||
STATIC FUNCTION MiddleMan(x)
|
||||
InnerModify(@x)
|
||||
RETURN NIL
|
||||
|
||||
STATIC FUNCTION InnerModify(y)
|
||||
y := 999
|
||||
RETURN NIL
|
||||
|
||||
|
||||
STATIC PROCEDURE TestByrefInLoop()
|
||||
LOCAL nSum := 0
|
||||
LOCAL i
|
||||
|
||||
FOR i := 1 TO 5
|
||||
AddToByRef(@nSum, i)
|
||||
NEXT
|
||||
|
||||
Assert("@byref in loop: sum 1..5 = 15", nSum == 15)
|
||||
|
||||
RETURN
|
||||
|
||||
STATIC FUNCTION AddToByRef(nAcc, nVal)
|
||||
nAcc := nAcc + nVal
|
||||
RETURN NIL
|
||||
|
||||
|
||||
STATIC PROCEDURE TestByrefPreservesType()
|
||||
LOCAL cStr := "hello"
|
||||
|
||||
AppendByRef(@cStr, " world")
|
||||
Assert("@byref string: 'hello world'", cStr == "hello world")
|
||||
|
||||
RETURN
|
||||
|
||||
STATIC FUNCTION AppendByRef(cParam, cSuffix)
|
||||
cParam := cParam + cSuffix
|
||||
RETURN NIL
|
||||
|
||||
|
||||
STATIC FUNCTION Assert(cLabel, lOK)
|
||||
IF lOK
|
||||
s_nPass++
|
||||
? " PASS:", cLabel
|
||||
ELSE
|
||||
s_nFail++
|
||||
? " FAIL:", cLabel
|
||||
ENDIF
|
||||
RETURN NIL
|
||||
Reference in New Issue
Block a user