Files
five/_FiveSql2/FIVE_COMPAT.md
Charles KWON OhJun 486e466592 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>
2026-04-11 11:35:37 +09:00

5.3 KiB

FiveSql2 — Five Compiler Compatibility Report

Date: 2026-04-08 Five Version: 1.0-dev FiveSql2: 14 PRG files, 10,335 lines, 13 classes, 157 test cases Status: Compiles and runs. 2 tests pass. SQL execution progresses through parser+executor but hits runtime issues in data access paths.


Issues Found & Fixed (25 total)

Compile-Time Issues (10 fixed)

# Issue Root Cause Fix
1 hbclass.ch include priority Harbour system include found before Five's Reorder: Five → user -I → Harbour
2 -I flag not supported build command only recognized -o Added -I dir and -Idir parsing
3 USE (expr) ALIAS (expr) ALIAS handler expected plain ident Added LPAREN check in both handlers
4 USE employees.dbf DOT consumed as member access Detect IDENT.IDENT as filename
5 CLASSDATA keyword Not recognized in CLASS body Added CLASSDATA/CLASSVAR handling
6 _seqErr unused variable No RECOVER body → unused var Added _ = _seqErr fallback
7 METHOD body xBase import hasXBaseCommands only scanned FuncDecl Added MethodDecl scanning
8 VIA "DBFCDX" VIA expected ident, not string Added STRING check
9 USE bareident Bare identifier treated as variable Detect bare ident as filename string
10 Deferred import (fmt/strings) Inline RTL adds imports after header Placeholder + post-patch

Runtime Issues (15 fixed)

# Issue Root Cause Fix
11 hb_FileExists missing Not implemented Added using os.Stat
12 HB_SECOND missing Not registered Implemented timestamp extraction
13 HB_ATOKENS missing Not registered Implemented string split
14 HB_CDPSELECT missing Not registered Stub (UTF-8)
15 DBSETINDEX missing Not registered Stub
16 Select() returns 0 Was a TODO stub Implemented FindByAlias/AreaAt
17 Alias() returns "" BaseArea.alias never set Added SetAlias in Open path
18 h["key"] := val crash ArrayPop only handled arrays Added hash branch
19 h["key"] read crash ArrayPush only handled arrays Added hash branch
20 BEGIN SEQUENCE swallows panic EndProc catches + doesn't re-panic Re-panic HbError for propagation
21 Code block capture fails `{ x
22 Case-insensitive locals localMap keys mixed case, lookups uppercase Normalize all to uppercase
23 Block param case Block params stored lowercase Uppercase in blockLocals
24 Method param case Method localMap used raw case Uppercase in emitMethodDeclStandalone
25 buildLocalMap case Function localMap used raw case Uppercase in buildLocalMap

Test Results

Test Suite Harbour Five Status
test_sql_standards 0 fail 0 fail PASS (parser tests)
test_sql1999 Section 4 all pass 2 PASS CHECK/UNIQUE basic insert works
test_sql1999 Overall 0 fail 2 PASS, 33 FAIL SQL execution exceptions

Passing Tests

  • 4d CHECK: valid insert (age=25) succeeds
  • 4e UNIQUE: new email allowed

Remaining Issues (3 categories)

A. SQL executor data access::aTables[i][3] etc. crash with "argument error []" because some hash/array nesting produces NIL intermediate values. This is NOT a Five language bug but likely a subtle OOP data flow issue.

B. &(expr) macro operator — 4 places in DDL (INDEX ON with dynamic expression). Requires runtime macro compiler. Workaround: pre-compile key expressions.

C. Section 6 crash — TestCombined calls functions without BEGIN SEQUENCE. Need to add error handling or fix the underlying function symbol resolution.


Verified Working Harbour Features

  • CLASS / DATA / METHOD / ENDCLASS / CLASSDATA
  • Standalone METHOD ... CLASS ClassName
  • :: self-reference + self field access
  • { => } hash literal + h[key] := val + h[key] read
  • hb_HHasKey, hb_HKeys, hb_HValues
  • Code block {|x| expr} with outer variable capture
  • ++ / -- operators
  • BEGIN SEQUENCE / RECOVER / END (nested, with proper panic propagation)
  • FOR EACH ... IN ... NEXT
  • SWITCH / CASE / OTHERWISE / END
  • USE (expr) / USE file.dbf / USE bareident / ALIAS (expr) / VIA "driver"
  • Select() / Alias() / dbSelectArea() / dbGoTop() / Eof() / dbSkip()
  • dbUseArea / dbAppend / FieldPut / FieldGet / dbCommit / dbCloseArea
  • dbCreate / FErase / hb_FileExists
  • AAdd / AScan / ASort / AClone with code blocks
  • ValType() / Len() / Upper() / Lower() / AllTrim() / SubStr()
  • ErrorBlock({|e| Break(e)})
  • STATIC variables / #include / #define / #ifdef

Performance

FiveSql2 compiled with Five produces native Go binaries. The RDD engine benchmarks:

Operation Harbour (C) Five (Go) Ratio
SEEK seq 50K 42ms 28ms Go 1.5x faster
SEEK rnd 50K 71ms 38ms Go 1.9x faster
SCAN 50K 3ms 1ms Go 3x faster
INDEX 50K 16ms 16ms Equal
CDX SEEK 50K 47ms 29ms Go 1.6x faster
CDX SCAN 50K 4ms 2ms Go 2x faster

Build

five build _FiveSql2/test/test_sql1999.prg _FiveSql2/src/*.prg \
    -I _FiveSql2/src -o test_sql
./test_sql