Compare commits
1 Commits
main
...
agent/bitt
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2a9318b1c |
@@ -15,28 +15,6 @@ typedef struct {
|
||||
|
||||
typedef struct { ziU8 keyLow; ziU8 keyHigh; ziU8 code; ziU8 flags; } Zi8AltSoundRecord;
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
ziU8 language;
|
||||
ziU8 getMode;
|
||||
ziU8 subLanguage;
|
||||
ziU8 context;
|
||||
ziU8 getOptions;
|
||||
ziWChar* elements;
|
||||
ziU8 elementCount;
|
||||
ziWChar* currentWord;
|
||||
ziU8 wordCharCount;
|
||||
ziWChar* candidates;
|
||||
ziU8 maxCandidates;
|
||||
ziU16 firstCandidate;
|
||||
ziU8 wordCandidates;
|
||||
ziU8 count;
|
||||
ziU8 letters;
|
||||
ziU8* scratch;
|
||||
ziPtr workspace;
|
||||
} Zi8OneKeyParam;
|
||||
|
||||
typedef struct {
|
||||
ziU8 countOnly;
|
||||
ziU8 maxSpellingLength;
|
||||
@@ -203,15 +181,15 @@ const ziWChar zi8PYfinalSpelling[64][4] = {
|
||||
|
||||
const unsigned long long Zi8SOpinyinArray = 0x0303010705000000ULL;
|
||||
|
||||
extern Zi8UInt Zi8Ord2Ord(ziU16, ziPtr);
|
||||
extern ziU16 Zi8Ord2Ord(ziU16, ziPtr);
|
||||
extern ziU8 Zi8LangSupported(ziU8, ziPtr);
|
||||
extern ziU16 Zi8GetTableCount(ziU8,ziU8,ziPtr);
|
||||
extern Zi8UInt Zi8GetTableAddress(ziU8,ziU8,ziPtr);
|
||||
extern void Zi8Memset();
|
||||
extern int _Zi8GetCandidates();
|
||||
extern void Zi8InitDupWordBuf();
|
||||
extern ziU16 Zi8GetPInfo(ziU16,ziWChar *,ziU8,ziPtr);
|
||||
extern ziU16 Zi8GetZInfo(ziU16,ziWChar *,ziU8,ziPtr);
|
||||
extern ziU32 Zi8GetTableAddress(ziU8,ziU8,ziPtr);
|
||||
extern void Zi8Memset(ziU8*,ziU32,ziS32);
|
||||
extern ziU8 _Zi8GetCandidates(ziGetParam*,ziPtr);
|
||||
extern void Zi8InitDupWordBuf(ziPtr);
|
||||
extern ziU32 Zi8GetPInfo(ziU32,ziWChar *,ziU8,ziPtr);
|
||||
extern ziU32 Zi8GetZInfo(ziU32,ziWChar *,ziU8,ziPtr);
|
||||
extern ziBool Zi8IsDupWordW(ziWChar *,ziU8,ziPtr);
|
||||
extern ziU8 Zi8GetFormatVersion(ziU8,ziPtr);
|
||||
extern ziU16 Zi8Uni2Ord(ziWChar,ziPtr);
|
||||
@@ -219,10 +197,10 @@ extern ziU16 Zi8GetPCode(ziU8 *,ziU8 *);
|
||||
extern ziU8 Zi8MatchOEMdata(ziWChar *,ziU8,ziU8,ziWChar *,ziU16,ziU8,ziU8,ziPtr);
|
||||
extern ziU8 Zi8MatchPUDdata(ziWChar *,ziU8,ziU8,ziWChar *,ziU16,ziU8,ziU8,ziPtr);
|
||||
extern ziWChar Zi8Ord2Uni(ziU16,ziPtr);
|
||||
extern Zi8UInt Zi8GetZHuwdPtr(ziU8 **,ziU16 *,ziPtr);
|
||||
extern int Zi8GetPyPhonetic();
|
||||
extern ziU8 Zi8GetBpmfPhonetic();
|
||||
extern int _Zi8CheckCandidates();
|
||||
extern ziU32 Zi8GetZHuwdPtr(ziU32*,ziU16*,ziPtr);
|
||||
extern ziU8 Zi8GetPyPhonetic(ziWChar*,ziU8,ziU16*,ziU16*,ziU8*,ziU16*,ziU16*,ziPtr);
|
||||
extern ziU8 Zi8GetBpmfPhonetic(ziWChar*,ziU8,ziU16*,ziU16*,ziU16*,ziU16*,ziPtr);
|
||||
extern ziU8 _Zi8CheckCandidates(ziGetParam*,ziPtr);
|
||||
|
||||
Zi8UInt Zi8SpellingZY(ziU16 *output,Zi8UInt key,ziU8 includeTone)
|
||||
{
|
||||
@@ -462,15 +440,15 @@ BACKWARD_SEARCH:
|
||||
goto BINARY_SEARCH;
|
||||
}
|
||||
}
|
||||
static Zi8UInt Zi8SetFindCand(ziU8 *foundCandidates,Zi8UInt ordinal,ziPtr work)
|
||||
static Zi8UInt Zi8SetFindCand(ziU8 *foundCandidates,ziU16 ordinal,ziPtr work)
|
||||
{
|
||||
Zi8UInt result;
|
||||
|
||||
ordinal = Zi8Ord2Ord(ordinal,work);
|
||||
result = (ziU8)((1 << ((int)(ordinal & 0xffff) % 8)) &
|
||||
foundCandidates[(int)(ordinal & 0xffff) / 8]);
|
||||
foundCandidates[(int)(ordinal & 0xffff) / 8] |=
|
||||
1 << ((int)(ordinal & 0xffff) % 8);
|
||||
result = (ziU8)((1 << ((int)ordinal % 8)) &
|
||||
foundCandidates[(int)ordinal / 8]);
|
||||
foundCandidates[(int)ordinal / 8] |=
|
||||
1 << ((int)ordinal % 8);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -506,7 +484,7 @@ LAB_return_false:
|
||||
return 0;
|
||||
}
|
||||
|
||||
Zi8UInt Zi8Get1KeyPressSpelling(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Zi8OneKeyWork *work)
|
||||
ziU32 Zi8Get1KeyPressSpelling(ziGetParam *params,Zi8OneKeyOptions *options,Zi8OneKeyWork *work)
|
||||
{
|
||||
ziU8 candidateCount;
|
||||
ziBool exactLength;
|
||||
@@ -531,18 +509,18 @@ Zi8UInt Zi8Get1KeyPressSpelling(Zi8OneKeyParam *params,Zi8OneKeyOptions *options
|
||||
ziU16 *output;
|
||||
ziU8 *savedSearchOrder;
|
||||
ziU16 spellingBuffer[8];
|
||||
Zi8OneKeyParam searchParams;
|
||||
ziGetParam searchParams;
|
||||
|
||||
candidateCount = 0;
|
||||
totalCandidates = 0;
|
||||
optionsMask = params->getOptions;
|
||||
params->count = 0;
|
||||
params->letters = 0;
|
||||
params->completion = 0;
|
||||
optionsMask = optionsMask & ~0x10;
|
||||
optionsMask = optionsMask & ~0x20;
|
||||
optionsMask = optionsMask & ~0x40;
|
||||
if (options->maxSpellingLength == '\0') {
|
||||
params->count = 0;
|
||||
params->letters = 0;
|
||||
Zi8LogError(100,work);
|
||||
return 0;
|
||||
}
|
||||
@@ -820,7 +798,7 @@ Zi8UInt Zi8Get1KeyPressSpelling(Zi8OneKeyParam *params,Zi8OneKeyOptions *options
|
||||
savedSearchCount = work->searchOrderCount;
|
||||
convertedInput = false;
|
||||
savedSearchFlags = work->searchFlags;
|
||||
Zi8Memset(&searchParams,0,0x2c);
|
||||
Zi8Memset((ziU8*)&searchParams,0,0x2c);
|
||||
searchParams.getMode = 0;
|
||||
searchParams.subLanguage = 0x80;
|
||||
searchParams.context = 1;
|
||||
@@ -918,7 +896,7 @@ Zi8UInt Zi8Get1KeyPressSpelling(Zi8OneKeyParam *params,Zi8OneKeyOptions *options
|
||||
work->searchFlags = savedSearchFlags;
|
||||
work->searchOrder = savedSearchOrder;
|
||||
work->searchOrderCount = savedSearchCount;
|
||||
params->count = searchParams.count;
|
||||
params->letters = searchParams.letters;
|
||||
work->spellingOnly = 0;
|
||||
if (convertedInput) {
|
||||
if (params->getMode == '\x03') {
|
||||
@@ -937,7 +915,7 @@ Zi8UInt Zi8Get1KeyPressSpelling(Zi8OneKeyParam *params,Zi8OneKeyOptions *options
|
||||
}
|
||||
}
|
||||
if ((options->countOnly == '\0') && (params->getMode == '\x03')) {
|
||||
for (tableIndex = 0; tableIndex < params->count;) {
|
||||
for (tableIndex = 0; tableIndex < params->letters;) {
|
||||
while (*output != 0) {
|
||||
if (*output != 0x27) {
|
||||
*output++ |= 0xf300;
|
||||
@@ -1022,12 +1000,12 @@ nextSpelling:
|
||||
}
|
||||
}
|
||||
finishSpelling:
|
||||
params->count = candidateCount;
|
||||
params->letters = candidateCount;
|
||||
Zi8LogError(100,work);
|
||||
return totalCandidates;
|
||||
}
|
||||
|
||||
int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Zi8OneKeyWork *work)
|
||||
ziU32 Zi8Get1KeyPressCandidates(ziGetParam *params,Zi8OneKeyOptions *options,Zi8OneKeyWork *work)
|
||||
{
|
||||
ziU16 wordBuffer [64];
|
||||
ziU16 spelling [8];
|
||||
@@ -1046,7 +1024,7 @@ int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Z
|
||||
ziU8 *phraseEntries;
|
||||
ziU16 *currentWord;
|
||||
ziU8 *entryCursor;
|
||||
ziU8 *userEntries;
|
||||
ziU32 userEntriesAddress;
|
||||
int duplicateIndex;
|
||||
ziU16 alternateCount;
|
||||
ziU16 ordinalCount;
|
||||
@@ -1148,8 +1126,8 @@ int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Z
|
||||
}
|
||||
languageMask = languageMask << 4;
|
||||
remaining = params->firstCandidate;
|
||||
params->count = 0;
|
||||
params->letters = 0;
|
||||
params->completion = 0;
|
||||
inputLength = params->elementCount;
|
||||
if (inputLength != 0) {
|
||||
while (inputLength != 0) {
|
||||
@@ -1271,7 +1249,7 @@ int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Z
|
||||
tableCursor = Zi8GetTableCount(1,9,work);
|
||||
}
|
||||
if (8 < inputLimit) {
|
||||
params->wordCandidates = 0;
|
||||
params->count = 0;
|
||||
goto finishCandidates;
|
||||
}
|
||||
for (index = 0; index < (int)(Zi8UInt)inputLimit; index++) {
|
||||
@@ -1357,7 +1335,7 @@ int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Z
|
||||
output[outputIndex++] = candidateCharacter;
|
||||
}
|
||||
if (candidateCount >= params->maxCandidates || outputIndex > outputLimit) {
|
||||
params->wordCandidates = candidateCount;
|
||||
params->count = candidateCount;
|
||||
goto finishCandidates;
|
||||
}
|
||||
} else {
|
||||
@@ -1426,7 +1404,7 @@ int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Z
|
||||
output[outputIndex++] = candidateCharacter;
|
||||
}
|
||||
if (candidateCount >= params->maxCandidates || outputIndex > outputLimit) {
|
||||
params->wordCandidates = candidateCount;
|
||||
params->count = candidateCount;
|
||||
goto finishCandidates;
|
||||
}
|
||||
} else {
|
||||
@@ -1547,7 +1525,7 @@ int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Z
|
||||
output[outputIndex++] = firstOrdinal;
|
||||
}
|
||||
if (candidateCount >= params->maxCandidates || outputIndex > outputLimit) {
|
||||
params->wordCandidates = candidateCount;
|
||||
params->count = candidateCount;
|
||||
goto finishCandidates;
|
||||
}
|
||||
} else {
|
||||
@@ -1568,7 +1546,7 @@ nextPhrase:
|
||||
else {
|
||||
finishPhrases:
|
||||
if (params->wordCharCount != '\0') {
|
||||
params->wordCandidates = candidateCount;
|
||||
params->count = candidateCount;
|
||||
}
|
||||
}
|
||||
if ((options->countOnly == '\0') && (tableCursor != 0)) {
|
||||
@@ -1629,11 +1607,11 @@ nextSortedOrdinal:
|
||||
;
|
||||
}
|
||||
}
|
||||
if ((options->countOnly == '\0') && (ziU8)Zi8GetZHuwdPtr(&userEntries,&userCount,work) != 0)
|
||||
if ((options->countOnly == '\0') && (ziU8)Zi8GetZHuwdPtr(&userEntriesAddress,&userCount,work) != 0)
|
||||
{
|
||||
for (phraseOrdinal = 0; phraseOrdinal < userCount;) {
|
||||
if ((params->elementCount == '\0') || ((userEntries[1] & 0x80) != 0)) {
|
||||
userOrdinal = (ziU16)(userEntries[1] & 0x7f) << 8 | (ziU16)userEntries[2];
|
||||
if ((params->elementCount == '\0') || ((((ziU8*)userEntriesAddress)[1] & 0x80) != 0)) {
|
||||
userOrdinal = (ziU16)(((ziU8*)userEntriesAddress)[1] & 0x7f) << 8 | (ziU16)((ziU8*)userEntriesAddress)[2];
|
||||
phraseTable = syllableTable + (Zi8UInt)userOrdinal * 0xc;
|
||||
if (((*phraseTable & languageMask) != 0) &&
|
||||
((characterSetTable == 0 || ((characterSet & characterSetTable[(Zi8UInt)userOrdinal]) != 0)))) {
|
||||
@@ -1677,7 +1655,7 @@ nextSortedOrdinal:
|
||||
}
|
||||
nextUserOrdinal:
|
||||
phraseOrdinal++;
|
||||
userEntries = userEntries + 3;
|
||||
userEntriesAddress = userEntriesAddress + 3;
|
||||
}
|
||||
}
|
||||
phraseTable = syllableTable;
|
||||
@@ -1740,12 +1718,12 @@ finishCandidates:
|
||||
if ((emitWords) && (outputIndex != 0)) {
|
||||
output[outputIndex++] = 0;
|
||||
}
|
||||
params->count = candidateCount;
|
||||
params->letters = candidateCount;
|
||||
Zi8LogError(100,work);
|
||||
return totalCandidates;
|
||||
}
|
||||
|
||||
Zi8UInt Zi8ZHCheckSpelling(ziU16 *input,ziU16 *spelling,Zi8UInt inputLength,char *work)
|
||||
ziBool Zi8ZHCheckSpelling(ziWChar *input,ziWChar *spelling,ziU8 inputLength,ziPtr work)
|
||||
{
|
||||
int index;
|
||||
ziU8 result;
|
||||
@@ -1760,11 +1738,11 @@ Zi8UInt Zi8ZHCheckSpelling(ziU16 *input,ziU16 *spelling,Zi8UInt inputLength,char
|
||||
int syllableStart;
|
||||
int syllableLength;
|
||||
Zi8UInt tableOffset;
|
||||
ziU8 candidateBuffer [32];
|
||||
ziU8 phoneticCodes [32];
|
||||
ziU8 phoneticMasks [32];
|
||||
ziWChar candidateBuffer [16];
|
||||
ziU16 phoneticCodes [16];
|
||||
ziU16 phoneticMasks [16];
|
||||
ziU16 convertedSpelling [64];
|
||||
Zi8OneKeyParam getParam;
|
||||
ziGetParam getParam;
|
||||
ziU8 maskLow;
|
||||
ziU8 codeLow;
|
||||
ziU8 maskHigh;
|
||||
@@ -1805,7 +1783,7 @@ Zi8UInt Zi8ZHCheckSpelling(ziU16 *input,ziU16 *spelling,Zi8UInt inputLength,char
|
||||
}
|
||||
index = 0;
|
||||
syllableStart = index;
|
||||
for (; index < (int)(inputLength & 0xff); index = index + 1) {
|
||||
for (; index < (int)inputLength; index = index + 1) {
|
||||
switch (spelling[index]) {
|
||||
case 0xf331:
|
||||
toneMask = 1;
|
||||
@@ -1876,7 +1854,7 @@ nextInputCharacter:
|
||||
}
|
||||
else {
|
||||
if ((input[index] == 0x27) || (input[index] == 0xf360)) {
|
||||
if (index < (int)(inputLength & 0xff)) {
|
||||
if (index < (int)inputLength) {
|
||||
convertedSpelling[index] = input[index] = spelling[index];
|
||||
}
|
||||
else {
|
||||
@@ -1918,7 +1896,7 @@ nextInputCharacter:
|
||||
getParam.elementCount = (ziU8)index;
|
||||
getParam.currentWord = 0;
|
||||
getParam.wordCharCount = 0;
|
||||
getParam.candidates = (ziWChar *)candidateBuffer;
|
||||
getParam.candidates = candidateBuffer;
|
||||
getParam.maxCandidates = 1;
|
||||
getParam.firstCandidate = 0;
|
||||
if ((ziU8)_Zi8CheckCandidates(&getParam,work) != 0) {
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
# One-key call and parameter contracts, 2026-10-03
|
||||
|
||||
Base: 674722c1; branch agent/bittle/onekey-contract-reconstruction.
|
||||
Owned source: zi81key.c only. This is source-type correctness work with no
|
||||
percentage gain. No callee implementation or shared header was changed.
|
||||
|
||||
## Retained, definition-backed boundaries
|
||||
|
||||
- Replaced the private ziGetParam replica with the existing shared type.
|
||||
The old replica's bytes at 0x20/0x21/0x22 were named
|
||||
wordCandidates/count/letters. The established shared type names those
|
||||
count/letters/completion. All accesses were renamed by their offsets;
|
||||
no field was moved or read/written at a different address. The unused last
|
||||
word retains the same target size. Dispatcher return declarations and the
|
||||
two public candidate-count return types now agree on their byte/full-word
|
||||
roles, respectively.
|
||||
- Added the actual _Zi8GetCandidates and _Zi8CheckCandidates prototypes,
|
||||
using ziGetParam pointers. Their explicit byte-result handling is preserved.
|
||||
- Recovered Zi8Ord2Ord's actual ziU16 return together with the local duplicate
|
||||
helper's ziU16 ordinal parameter. Ordinary typed uses replace the explicit
|
||||
halfword masks of the former full-word local. Correcting only the external
|
||||
return lost the exact helper; this coherent pair preserves all 50 of its
|
||||
instructions and every caller instruction.
|
||||
- Zi8GetPInfo and Zi8GetZInfo actually accept a ziU32 phonetic code and return
|
||||
ziU32. Corrected their local declarations; the existing caller's explicit
|
||||
byte result conversion remains.
|
||||
- Added the actual Py/Bpmf phonetic prototypes. This exposed two scratch
|
||||
arrays declared as 32 bytes despite receiving 16 halfword outputs. They
|
||||
are now 16-element ziU16 arrays, preserving their 32-byte extents. The
|
||||
candidate output buffer is likewise 16 ziWChars instead of 32 bytes plus
|
||||
a cast. No new storage or alignment directive was added.
|
||||
- Zi8GetZHuwdPtr writes a native ziU32 address through its first parameter.
|
||||
Its local declaration and address-taken receiving variable now use that
|
||||
actual type. Byte decoding uses an explicit view of userEntriesAddress;
|
||||
address stepping remains three bytes. This removes the incompatible
|
||||
pointer-to-pointer/integer-output contract without an extra temporary.
|
||||
- Zi8GetTableAddress, Zi8Memset and Zi8InitDupWordBuf local declarations now
|
||||
agree with their actual definitions. The parameter object is cleared
|
||||
through the memset callee's byte view.
|
||||
- Zi8ZHCheckSpelling now agrees with its caller in zi8alpha.c: byte Boolean
|
||||
return, byte input count, and opaque workspace pointer. Its result was
|
||||
already a byte; removing the input's redundant full-word masks preserves
|
||||
the entire existing exact body.
|
||||
|
||||
The authoritative definitions are in zi8getc2.c, zi8misc.c, zi8cinfo.c,
|
||||
zi8match.c and zi8ZHuwd.c. The public count-return declarations are in
|
||||
zi8getc2.c; the spelling-check declaration is in zi8alpha.c. Only the owned
|
||||
file was edited. The private option/work views remain in place; this is not
|
||||
an attempt to consolidate every library type or repair every declaration.
|
||||
|
||||
## Isolated trials
|
||||
|
||||
- PInfo/ZInfo actual declaration pair: neutral
|
||||
- Bare Py/Bpmf prototypes: compile error exposing byte-array/halfword-pointer
|
||||
disagreement; fixed by correctly typed same-size output buffers
|
||||
- Ord2Ord return only: duplicate helper 100 -> 98.8%; rejected
|
||||
- Ord2Ord return plus typed ordinal: original exact helper restored, neutral
|
||||
- Shared request type and offset-preserving field names: neutral
|
||||
- Typed dispatcher prototypes with shared request type: neutral
|
||||
- Phonetic and candidate halfword output buffers: neutral
|
||||
- Native user-dictionary address contract: neutral
|
||||
- Public return/input boundaries: neutral
|
||||
- Final retained combined contracts: all code/data and metrics unchanged
|
||||
|
||||
Other coherent local spelling/alternate-phonetic parameter-width trials were
|
||||
neutral and are not included without an external declaration disagreement.
|
||||
The PUD return/caller-byte trial on the new baseline dropped unit fuzzy to
|
||||
97.782295% and exact data 1280 -> 1232; it was rejected and is not included.
|
||||
No blanket byte-cast, declaration-order or register-allocation sweep was used.
|
||||
|
||||
## Verification
|
||||
|
||||
Baseline report: /tmp/ezi-onekey-contract-baseline.json.
|
||||
Baseline object: /tmp/ezi-onekey-contract/baseline.o.
|
||||
Final report: /tmp/ezi-onekey-focused-full-report.json.
|
||||
Full build: /tmp/ezi-onekey-focused-final-build.log.
|
||||
Detailed gates: /tmp/ezi-onekey-focused-verification.txt.
|
||||
|
||||
All 1027 unit measures are unchanged. Unit fuzzy remains 98.23523%; main
|
||||
candidate engine remains 96.41927%. Exact functions remain 5/9, exact code
|
||||
3952/21460, and matched data 1280/1388. No new exact function or percentage
|
||||
gain is claimed.
|
||||
|
||||
All owned emitted sections have baseline-identical lengths, payloads and
|
||||
canonical relocations: .text 21496, .rodata 1152, .data 44, .sdata2 8,
|
||||
extab 72 and extabindex 108. All nine functions have baseline-identical
|
||||
disassembly, not only equivalent scores. Each of the five existing exact
|
||||
functions still has ctxdiff diffs 0 and identical instruction counts:
|
||||
Zi8IsMatch1Key 97, MatchAltSound1Key 341, Zi8SetFindCand 50,
|
||||
ZiIsSupportedPhonetic 81, Zi8ZHCheckSpelling 419.
|
||||
|
||||
Pool first: identical and empty. Full 43U build passes with the approved
|
||||
wrapper and WIBO_SJIS_MISSING_IMPORTS=1. DOL SHA1:
|
||||
26116613f624061ba99c8d1a299aaa6efa85670d.
|
||||
git diff --check passes. No linking, remote, metadata, new assembly, volatile
|
||||
workaround, dummy storage, undefined value or forced-register change.
|
||||
Reference in New Issue
Block a user