This commit is contained in:
Alvin-Zilverstand committed 2026-10-08 01:02:30 +02:00
1 parent 96cd1ac97d
commit 6dfe517094
33 files changed
+9970 -3177

No files matched your search

+289
View File
@@ -92,3 +92,292 @@ exercise pointer-to-array parameters/globals/locals, arrays of row pointers,
grouped names, casts and sizeof array type names. Rejections verify incomplete
pointee sizing/arithmetic, arrays of void, invalid casts and incompatible row
pointer declarations. Kernel compilation still produces 36,009 words.
Shift assignments and pointer/integer operator constraints bring the suite to
615 checks. Native execution covers destination side effects, chained assignment,
precedence and signed/zero shifts. Negative cases cover evaluated and sizeof
pointer operands for integer operators.
Composite function declaration types bring the suite to 631 checks. Native
programs combine incomplete and complete row-pointer declarations, including
additional indirection. Negative cases verify conflicting completions, element
types and pointer depths remain rejected.
Compound-assignment and unevaluated operand checks bring the suite to 671 checks.
Native tests retain row-pointer offset scaling and verify sizeof suppresses
side effects. Negative cases reject pointer difference/shift assignments and
array, literal or void targets in unevaluated modification expressions.
File-scope extern/tentative object declarations bring the suite to 695 checks.
Native tests verify one shared allocation, initialized values and relocated
pointers, completed arrays and zero-filled tentative storage. Negative tests
verify conflicting declarations, duplicate definitions and unresolved extern
references reject while preserving prior output files.
Block-scope extern objects bring the suite to 727 checks. Native execution
verifies scoped global aliases, shadowing without altering an outer local,
repeated declarations and completed array types. Rejections verify names do not
escape their declaring block/function and that conflicting/initialized block
extern declarations fail. The kernel remains 36,009 words.
Function-local static storage brings the suite to 755 checks. Native programs
verify persistence, private same-name objects, arrays/strings and static pointer
relocations. Negative cases reject runtime initializers, automatic addresses,
duplicate declarations and names escaping their declaring scope.
File-scope static declarations bring the suite to 783 checks. Native programs
combine internal objects/functions, relocated pointers and extern inheritance;
negative tests reject linkage conflicts and incomplete internal tentative arrays.
Constant sizeof initialization brings the suite to 787 checks. Native tests
exercise type/literal bounds and case labels, global initialized sizes and local
static sizeof automatic arrays and side-effect expressions without evaluation.
Parser type binding tests bring the suite to 807 checks. Native execution verifies
named sizeof bounds/case labels, array parameter adjustment, shadowing and block/
loop scope restoration. Rejection tests cover later, escaped and undeclared
bindings. Kernel compilation still produces 36,009 words.
Scoped typedef tests bring the suite to 843 checks. Native execution covers
scalar/pointer/array aliases, casts/parameters/sizeof, nested alias and object
shadowing, scope restoration and void aliases for no-argument functions.
Rejection tests verify ordinary-namespace conflicts and escaped/invalid aliases.
Enum tests bring the suite to 887 checks. Native programs cover distinct enum
objects, scoped constants/tags, explicit/automatic values, aliases, bounds and
switch labels. Negative cases verify namespace/type conflicts, invalid values
and out-of-scope or nonmodifiable constants reject.
Boolean type tests bring the suite to 899 checks. Native execution verifies
normalized storage across initialization, arrays, casts, calls, assignments and
modification; negative cases reject conflicting object/parameter declarations.
Unsigned int tests bring the suite to 915 checks. Native execution covers
high-bit comparisons, mixed signed operands, division/remainder, logical shifts,
casts and wraparound. Negative cases reject conflicting declarations and pointer
division. Conditional helper inclusion keeps the kernel at 36,009 words.
## Initial bob32 CPU migration
The widened emulator passes 42 direct CPU checks, 915 OS/compiler checks and
28 native console checks. CPU cases cover immediate sign extension, legacy and
wide overflow/flags, 32-bit load/store, B32K loading, guest boot transfer and
execution, and B16K compatibility selection. This does not establish a complete
bob32 ABI or whole-repository audit; see BOB32_MIGRATION.md for remaining work.
Trap/return-register audit fixes bring the direct CPU suite to 47 checks. New
cases verify signed compatibility return addresses, native wide return addresses,
supervised wide result preservation and a string word whose low 16 bits are zero.
The string case also requires the trap instruction register to remain intact.
The OS/compiler and console suites remain at 915 and 28 checks respectively.
Image/argument audit cases bring the direct suite to 65 checks. Subprocesses
require malformed B32K images to reject; numeric argument tests cover boundaries,
overflow and malformed strings, and a limited emulator run must return status 2.
Compatibility suites still pass 915 OS/compiler and 28 console checks.
Assembler input/data audit cases bring the direct suite to 73 checks. Cases cover
one string terminator, CRLF registers, complete/range-checked fill words, oversized
physical lines, all 65,536 slots and string overflow rejection before memory writes.
The repository demo plus 915 OS/compiler and 28 console checks pass.
Assembler operand tests bring the direct suite to 94 checks. Every immediate
operand family rejects malformed decimal text, invalid register-shaped tokens
and overflow. Positive tests preserve field clamping, relative/indirect calls
and the documented NOP encoding. Compatibility suites remain at 915 and 28.
Storage metadata/service tests bring the direct suite to 105 checks. Cases cover
descriptor arithmetic boundaries, wide-mode rejection, valid empty/text metadata,
invalid flags/kinds/lengths, content terminators and duplicate names. Existing
persistence cases retain failed-restore RAM preservation; 915 OS/compiler and
28 native console checks pass.
Wide instruction-boundary checks bring the direct suite to 107 checks. Reserved
upper bits must fault under supervision with parent state restored; sign-extended
legacy instructions remain accepted. Native ROM execution and compatibility
suites continue to pass (915 OS/compiler, 28 console).
Native storage verification: B32S round-trip preserves 0x12345678; upper-byte checksum corruption and cross-mode restore reject without changing RAM. Legacy OS save/restore remains covered by 915 OS/compiler checks. All 111 CPU/storage/assembler and 28 native console checks passed.
Host specifier audit: runtime coverage exercises typedefs, reordered function declarations/definitions, signed arrays, unsigned division and unsigned casts/right shifts. Six invalid specifier combinations are rejected while preserving existing output files. All 943 OS/compiler checks passed; regenerating the 36,009-word kernel produced the identical B16K image.
Host escape audit: runtime checks cover missing simple escapes, hexadecimal/octal 255, array length and terminator. Rejection coverage includes hexadecimal 256, a long overflowing hexadecimal sequence, octal 256, and direct unterminated string/character escapes bypassing preprocessing. Lexer failures preserve both prior output artifacts. Kernel rebuild remains byte-for-byte identical.
Storage address validation: direct service and actual trap execution reject native high-bit descriptor addresses. Changed-kernel B32S restore preserves text and marks binaries unused. All 115 CPU/storage/assembler, 967 OS/compiler and 28 native console checks passed.
Host input/lexer verification: direct malformed-source fixtures cover newline-containing string/character literals, 08, 1u2, 1_foo and a zero byte followed by otherwise ignored source. Existing assembly and binary outputs survive input failures. The full OS/compiler suite passed 981 checks, and the regenerated 36,009-word kernel matches the previous image.
Pointer ordering verification: one 4,096-element array crosses 0x8000, and all four relational operators compare its first/last elements and equality boundaries correctly. Additional runtime coverage compares compatible row pointers with incomplete/complete bounds. Invalid relational operand types, including sizeof, are rejected. All 1,005 OS/compiler checks passed; the 36,009-word kernel image remains unchanged.
Compiler output audit: seven collision cases verify preservation of the input, BASM, B16K and map, including Windows case and relative-path aliases. All 1,040 OS/compiler checks passed. An extensionless binary in build/output.audit produces image.map in that directory; the regenerated kernel image remains identical.
Void-expression verification: a runtime fixture counts effects through discarded calls, casts, comma and void conditionals. Fifteen invalid contexts cover operators, assignment, casts, sizeof, conditionals and all loop/if conditions. All 1,104 OS/compiler checks passed; the regenerated kernel image remains unchanged.
Return/argument verification: six invalid programs cover void/value return mismatches and ordinary/trap function arguments. All 1,128 OS/compiler checks passed; kernel regeneration produced the identical 36,009-word image.
Switch type verification: five invalid programs cover pointer, array and void conditions plus pointer/void labels. Runtime coverage verifies unsigned 65535, enum and _Bool dispatch. All 1,152 OS/compiler checks passed; the rebuilt 36,009-word kernel image is unchanged.
Const spelling verification: runtime fixture covers qualified globals, parameters, typedefs, enums, byte arrays, pointer qualifiers, repeated qualifiers and sizeof spellings. All 1,156 OS/compiler checks passed; the rebuilt kernel image is unchanged. These checks do not establish qualifier enforcement.
Build-tool audit: read tools/build.c in full, checked command status propagation and platform path handling, and added checked build-directory creation/type and Windows compiler PATH updates. A regular-file build entry fails before compiler invocation. Full build --test passed 115 CPU/storage/assembler, 1,156 OS/compiler and 28 native console checks. CPU snapshot tests now use a platform-specific environment helper rather than unconditional Windows calls; the POSIX branch remains unverified on a POSIX host.
Decoder verification: eight mode/instruction combinations check malformed NOP, NOT, JSRR and RET and parent register/PC restoration. All 123 CPU/storage/assembler, 1,156 OS/compiler and 28 native console checks passed.
Pointer subtraction verification: runtime cases compare enum/int element pointers and row pointers in both directions and inside sizeof. Three invalid cases reject distinct enum tags, incompatible row extents and incomplete row types. All 1,172 OS/compiler checks passed; the rebuilt 36,009-word kernel image is unchanged.
Conditional pointer verification: runtime cases verify complete/incomplete array composite sizes, zero/null branches, arithmetic zero and object/void pointer combinations. Four invalid programs reject incompatible pointers, nonzero/nonconstant integer branches and invalid sizeof operands. All 1,192 OS/compiler checks passed; the rebuilt 36,009-word kernel is unchanged.
Arithmetic helper review: multiplication replaced with a bounded word-mask loop. Runtime verification repeats 32767 squared and INT_MIN times 32767 sixty-four times, and covers zero, negative operands, INT_MIN wrap and unsigned 65535 squared. All 1,196 OS/compiler and 28 native console checks passed with the rebuilt 36,005-word kernel.
Resident multiplication verification: go product.c compiles and runs sixty-four repeated large products, including the signed minimum value expressed as -32767-1, plus negative and wrapping products. No compile error or supervised timeout occurs, and output is bob! with Exit 0. All 1,200 OS/compiler checks passed. cc_multiply is a wrapper around the shared host-generated helper, so the prior claim of a separate unchanged resident implementation has been corrected. The resident lexer still rejects decimal 32768, including the literal in -32768; broader literal typing remains open.
Resident octal verification: go accepts 010, 077 and 0177777 with expected values and prints bob!. Invalid 09 and overflowing 0200000 are followed by a successful go bob.c recovery. Existing malformed-source cases cover consolidated cc_fail handling. All 1,206 OS/compiler and 28 native console checks passed with the rebuilt 36,092-word kernel.
Code generation verification: the complete 1,206 OS/compiler checks and 28 native console checks passed after removing empty stack adjustments and compacting target-equivalent literals. The rebuilt 35,909-word kernel executes resident compilation, arithmetic, editor and storage paths successfully.
Resident escape and double-negation verification: go escapes.c checks all six additional spellings and prints bob!. Host runtime checks cover double negation of zero, pointers, negative/high-bit values and increments without duplicate effects. All 1,213 OS/compiler and 28 native console checks passed with the 36,096-word kernel.
Frame omission verification: recursion through no-parameter/no-local functions returns the expected result while a caller's automatic local remains intact. All 1,217 OS/compiler checks passed; 28 native console checks passed against the same rebuilt 36,054-word kernel.
Resident line-break verification: malformed multiline string and character literals both fail, then go bob.c succeeds. Existing literal/arithmetic cases exercise unary numeric folding. All 1,220 OS/compiler checks and 28 native console checks passed with the 36,041-word kernel.
Resident concatenation verification: go joined.c merges literals separated by a comment, an empty piece and a newline into bob!, then exits successfully. All 1,223 OS/compiler and 28 native console checks passed with the 36,071-word kernel.
Resident code limit verification: a source that fits the RAM text file but emits more than 511 words fails compilation into an existing output name. The previous executable runs without fault, and a subsequent go bob.c succeeds. All 1,227 OS/compiler checks and 28 native console checks passed with the 36,080-word kernel.
Signed division verification: repeated INT_MIN/1, INT_MAX/1 and INT_MAX/-1 calculations complete; all operand sign combinations and remainder signs are checked. All 1,231 OS/compiler checks and 28 native console checks passed with the 36,093-word kernel.
Assembly prompt audit: oversized filename input now drains through its line ending before retrying, rather than treating the leftover text as another filename. A 300-character input followed by valid BASM recovers and prints bob!. All 125 CPU/storage/assembler, 1,231 OS/compiler and 28 native console checks passed.
Constant type verification: four static initializers reject void/value conditional branches, void logical operands despite short-circuiting, and casts from void to a value. All 1,247 OS/compiler checks passed, and kernel regeneration matches the current 36,093-word image.
Native input/run boundary verification: actual trap execution rejects a high-bit entry address, and supervised input calls reject high-bit address/capacity arguments without modifying the destination. All 128 CPU/storage/assembler, 1,247 OS/compiler and 28 native console checks passed.
Image/source I/O review: readWord now distinguishes read error from truncated input. bootImage checks stream error and close status after checksum/exact-length validation; assemble checks close failures before announcing execution. Diagnostics identify both word-width formats. Existing truncated/corrupt image and assembly checks, plus all 128 CPU/storage/assembler, 1,247 OS/compiler and 28 native console checks, passed. Read/close failures have not been fault-injected.
Native disk argument verification: subprocess fixtures individually set upper bits in destination, offset and count and fail at trap execution. Existing B32K boot/transfer checks still pass. All 131 CPU/storage/assembler, 1,247 OS/compiler and 28 native console checks passed.
Windows console input audit: terminalKey now checks GetConsoleMode and SetConsoleMode results before using the mode, and returns EOF rather than zero when ReadConsoleInput stops without a key. This avoids an uninitialized mode and ambiguous failed-read result. All 28 native console and 1,247 OS/compiler checks passed; Windows API failure paths have not been fault-injected.
Boundary evidence refinement: native disk argument subprocess cases now verify the intended fault diagnostic, excluding unrelated process failures. Assembly filename handling accepts a full 255-character name followed by CRLF; an adjacent oversized line is still consumed before valid BASM execution. All 135 CPU/storage/assembler, 1,247 OS/compiler and 28 native console checks passed. CRLF tests ran on Windows; untranslated POSIX input remains unverified on its native host.
Assembly source boundary audit: a 255-character source line followed by CRLF is accepted without losing the following .fill instruction. A 256-character line still fails. All 137 CPU/storage/assembler, 1,247 OS/compiler and 28 native console checks passed.
Pointer equality verification: runtime coverage checks symmetric object/void and null comparisons, arithmetic zero, sizeof and self equality. Four invalid programs reject nonzero integers, ordinary zero-valued variables, incompatible pointers and invalid sizeof operands. All 1,267 OS/compiler checks passed; the regenerated 36,093-word kernel image is unchanged.
Assignment compatibility verification: runtime cases check object/void pointer assignments, null arithmetic constants, _Bool normalization and sizeof. Four invalid assignments are rejected. Kernel source conversion is explicit and regeneration matches the current image. All 1,287 OS/compiler checks passed.
Return conversion verification: runtime cases check object/void pointer returns, arithmetic null returns and pointer-to-_Bool normalization. Three invalid programs reject nonzero integer, incompatible pointer and implicit pointer-to-integer returns. All 1,303 OS/compiler checks passed; the regenerated kernel image is unchanged.
Function argument conversion verification: a runtime program checks compatible object/void pointers, arithmetic null constants and pointer-to-_Bool normalization. Three invalid programs reject nonzero integer-to-pointer, incompatible pointer and pointer-to-integer arguments. All 137 CPU/storage/assembler, 1,319 OS/compiler and 28 native console checks passed. Kernel binary hash is unchanged after generic memory API signatures and explicit text casts.
Initializer conversion verification: nine invalid programs cover automatic and global pointers, pointer arrays, block-static objects, pointer-to-integer initialization and void-valued initialization. A runtime fixture covers valid local/global/array/static object pointers, object/void conversions, null constants and pointer-to-_Bool normalization. All 1,359 OS/compiler checks passed. The rebuilt kernel binary hash matches the existing 36,093-word image.
Trap argument conversion verification: seven invalid sources reject nonzero integer text pointers, incompatible text/descriptor pointers, pointer capacities, pointer characters and implicit pointer entry addresses. A runtime fixture passes a void pointer to bob_puts and prints bob!. All 1,391 OS/compiler checks passed; regenerated kernel hash matches the existing image.
Unevaluated call verification: five negative sources reject wrong parameter counts, nonzero integer pointers, incompatible pointers and invalid declared trap arguments inside sizeof. A runtime fixture verifies valid object/void pointer arguments and increment expressions are not evaluated. Existing early empty-list/later definition cases still pass. All 1,415 OS/compiler checks passed, and the regenerated 36,093-word kernel hash is unchanged.
Subscript constraint verification: four invalid programs reject void-valued index operands in both orders and indexing through void or incomplete-array element pointers inside sizeof. A runtime fixture verifies unsigned reversed indexing, row size and scalar element size in multidimensional arrays. All 1,435 OS/compiler checks passed; regenerated kernel binary hash is unchanged.
Nested sizeof/address verification: eight invalid programs cover inner void size, invalid call arguments, invalid indexing/assignments, and address-of constants, arithmetic, increments and casts. Runtime fixtures verify nested sizeof suppresses increments and pointers to string-literal arrays preserve full array size and contents. All 1,475 OS/compiler checks passed. The regenerated kernel hash is unchanged at 36,093 words.
Static string address verification: a runtime fixture checks global and block-static pointers to whole literal arrays, their complete sizes and terminators, a string-element address, and scaled one-past pointer arithmetic. All 1,479 OS/compiler checks passed. Kernel regeneration produces the same 36,093-word binary hash.
Conditional static relocation verification: runtime cases cover true/false object address selection, null selection, sizeof-based string selection and nested block-static pointer selection. Negative sources reject variable conditions and incompatible pointer branches. All 1,491 OS/compiler checks passed. Kernel binary regeneration matches the existing 36,093-word image.
Numeric pointer constant verification: a runtime fixture compares initialized pointer-to-array values against runtime arithmetic for forward/reversed addition, subtraction and pointer difference at guest addresses above 0x8000. All 1,495 OS/compiler checks passed. The regenerated 36,093-word kernel binary hash is unchanged.
Unary code-generation verification: three negative programs reject prefix/postfix increments of void lvalues and array increment. Existing runtime fixtures for numeric unary operators, pointer/Boolean increments and literal-array addresses still pass. All 1,507 OS/compiler checks passed. The regenerated 36,093-word kernel hash is unchanged.
Static Boolean address verification: a runtime fixture checks implicit object/string addresses, explicit Boolean address casts, null pointers, Boolean arrays and block-static address initialization. All 1,511 OS/compiler checks passed; regenerated kernel hash matches the existing 36,093-word image.
Relocation boundary verification: a generated source with large static arrays reaches the 65,536-word emission limit while adding pointer relocations. Compilation rejects with the intended code/relocation diagnostic and preserves existing BASM and binary outputs. All 1,516 OS/compiler checks passed. Kernel regeneration matches the existing 36,093-word binary hash. The fixture exercises code-capacity rejection through relocation emission; independent relocation-capacity saturation is not claimed.
Long literal verification: a generated guest program compiles a single 9,000-character literal and checks its last character and terminator before printing bob!. Existing escape, embedded-NUL, malformed literal and code-limit fixtures still pass. All 1,520 OS/compiler checks passed; regenerated kernel hash matches the existing 36,093-word binary. Allocation failure is checked in code but was not fault-injected.
Adjacent literal scaling verification: a generated program joins 9,000 adjacent one-character literals and verifies the final character and terminator before printing bob!. Existing embedded-NUL and ordinary concatenation fixtures remain passing. All 1,524 OS/compiler checks passed. The kernel binary hash is unchanged at 36,093 words. Linear allocation/copy behavior follows from the implementation; no host peak-memory benchmark was recorded.
Integer constant expression type verification: three invalid sources reject pointer-valued expressions used as array bounds, explicit enum values and array designator indexes. All 1,536 OS/compiler checks passed. Kernel regeneration matches the existing 36,093-word image.
Jump bookkeeping verification: host compiler rebuild and kernel regeneration pass after routing jump records through a checked append helper. All 1,536 OS/compiler checks passed; regenerated kernel hash matches the existing 36,093-word image. The explicit jump-table overflow guard is defensive because token/code limits generally fire earlier.
Generated-label bookkeeping now checks the signed serial before incrementing, so future larger outputs fail with a defined diagnostic instead of overflowing label names. The existing 65,536-word code capacity generally rejects first; a dedicated serial-saturation fixture would require constructing a larger-than-emittable AST and was not added.
Switch-context validation now rejects case/default labels outside switches during parsing and caps nested switches at 64 before recursive parsing. File-scope and function-scope invalid labels are covered. All 1,540 OS/compiler checks pass; legal labels later in a switch body remain accepted regardless of earlier break statements.
Integer constant expression syntax is now enforced for array bounds, enumerators, designator indexes and case labels. New negative inputs cover calls and side effects in bounds, designators and cases. The host OS/compiler suite passes all 1,556 checks, and the compiled kernel remains 36,093 words.
ICE type validation now walks casts, unary/binary operands and conditional operands, preventing void or pointer operands from being laundered through sizeof or an integer cast. Added array-bound and enumerator regressions for sizeof of a void cast. The full OS/compiler suite passes 1,564 checks; kernel image size and hash remain unchanged.
Explicit unsigned enum values whose result is outside signed 16-bit int range now fail instead of wrapping into a negative enumerator. The suite includes the 32768U rejection; existing negative and positive signed boundary enums continue to compile. All 1,568 OS/compiler checks pass, and the kernel image is unchanged.
Assembler input now reads bounded physical lines byte by byte and rejects embedded NUL bytes, which fgets/C-string parsing previously treated as end-of-line. CRLF, exact 255-character lines, final lines without newline, and overlong lines remain covered. The direct CPU/assembler suite passes 138 checks, including an embedded-NUL input; OS/compiler suite passes 1,568.
The assembler's `not` instruction now validates exact arity and requires a valid register in the two-register form. Previously `not r0 r8` silently encoded as `not r0`, and a fourth token was ignored. New cases cover invalid/missing/extra operands. Direct suite: 141 checks passed; OS/compiler suite: 1,568 passed.
Load/store register validation now rejects all negative `parseReg` results, not only the missing-token sentinel. Invalid register names previously reached negative shifts and malformed encodings. Added malformed-name and out-of-range cases for LD/LDI/LDR/ST/STI/STR operands. Direct CPU suite: 150 checks passed; OS/compiler suite: 1,568 passed.
The assembler now rejects trap vectors above 11, matching the emulator's implemented trap table; values 12–15 previously assembled and then faulted at runtime. Direct tests cover vectors 12 and 15. Reserved register-form ADD/AND bits also fault in both CPU modes. CPU suite: 156 passed; OS/compiler suite: 1,568 passed.
Host expression parsing now rejects nesting beyond 256 calls, protecting the compiler process from deeply nested parentheses/unary/right-associative expressions exhausting its C stack. A generated 400-level array-bound source verifies the diagnostic. OS/compiler suite: 1,573 checks passed. Recompiled kernel remains 36,093 words and matches SHA-256 F4B1175B84A8BFE2ABFB192D51CBA1E000D7EDDB52B9CECC2C4306E74BF0A4AF.
Host const scalar enforcement now tracks const declarations and typedef aliases through locals, globals and scalar parameters. Assignments and increments reject modification, including within sizeof and array-bound constant-expression parsing. Pointer, array and pointee qualification still need full type-system support. The suite passes 1,601 checks; regenerated kernel remains 36,093 words.
Direct const pointer declarators and top-level const pointer typedef aliases now retain their object qualifier, so pointer assignment and increment reject for globals, locals and parameters. `typedef const int *P` remains assignable as a pointer, confirming the pointee qualifier is distinct; enforcing pointee and array-element const remains incomplete. The OS/compiler suite passes 1,629 checks.
Pointer types and array types now retain const qualification. Assignments/increments through `*p` and `p[i]` reject for const pointees/elements; adding const to a pointer conversion is allowed, while dropping it rejects recursively through pointer levels, address-of, and conditional expressions. `bob_puts` now correctly accepts a const string. Function redeclaration checks preserve pointed-to qualifiers while ignoring top-level parameter qualifiers. Some nested qualified-declarator forms remain unfinished. OS/compiler suite: 1,697 checks passed.
Native program counters and effective addresses now retain 32 bits, with lazy sparse pages above the existing 64K-word low-memory array. JMP/JSRR/RET/PUTS preserve high addresses; LDR/STR and LDI/STI operate there, supervised programs can read/write high data, and GETS/boot-disk writes accept high destinations. B16 mode still wraps at 16 bits. B32K v2 adds 32-bit image origin, entry, length and checksum fields and can boot at any address, including the top two addressable words. Version 1 and B16 images retain their old format. Tests cover malformed v2 headers, payload checksums and command-line high-origin boot. CPU suite: 178 checks; OS/compiler: 1,697; console: 28. The current image payload remains limited to 65,536 words, and the C compiler/OS still target bob16.
The host C compiler now accepts `--wide` to emit native bob32 instructions as B32K v2 images. Wide mode supports 32-bit integer literals, data, arithmetic helpers for multiply/divide/modulo, signed and unsigned comparisons, shifts and bitwise operations, and accepts long/long long as 32-bit aliases with standard integer literal suffix order validation. The word-addressed target uses one C byte per word, so sizeof reports words and remains consistent with current array and pointer layout. Default bob16 output retains its old format. Wide output emits only functions reachable from main, following explicit calls, operator helper dependencies, array indexing, and bob_address references. A helper-free guest compiles to 23 words. `--wide-app` emits B32K v2 images at the supervised app origin, and the bob32 shell's `run32 PATH` validates the image before loading it into high memory; sparse pages are preflighted so allocation failure leaves the app region untouched. A compatibility audit found that bob16 apps can overwrite the tail of the low-address B32 kernel; supervised return now restores any overlapping kernel image words. The B32 resident compiler also emits kind-2 native programs at `0x10000`, using 32-bit literals and arithmetic, and B32S snapshots preserve these program files. It supports right-associative `?:` with selected-branch-only evaluation and `do/while` with `break`/`continue`; resident regressions check nested conditionals, skipped side effects, first-iteration behavior, early exits and continue-to-condition behavior. The bob16 compiler retains its previous behavior because its kernel image is already at the memory limit. Regression coverage also compiles and runs addition, multiplication, division, remainder and local-variable arithmetic, retains the legacy kind-1 bob16 execution path, and snapshots native files. End-to-end tests cover direct `.org` BASM execution, missing-image recovery, B32S save/restore, shell editing and 8-digit hex output. Full C conformance remains incomplete. Current suite: CPU 179, OS/compiler 1,745, console 28.
Resident B32 assignment expressions: right-associative chained assignment returns the stored value, compound assignment works inside expressions, and `<<=`/`>>=` are recognized and executed. Shell integration uses short editor input lines (below the command limit), frees source slots after each run, and asserts all nine successful B32 shell programs. bob16 image remains 36,093 words. Full suite: CPU 189, OS/compiler 1,746, native console 28.
Supervised-store boundary audit found that the B32 condition rejected writes in `0x100000..0x10FFFF` but accidentally allowed all later sparse-memory addresses. The guard now enforces `[0x10000,0x100000)` for native apps and `[0x9000,0xE000)` for B16 legacy apps. B32 legacy apps use `[0xB000,0xE000)`. Direct CPU regressions accept the final B32 app word and reject below-range, end, former-hole, arbitrary-high and maximum addresses without modifying them. Suite: CPU 189, OS/compiler 1,746, console 28.
B32 external-image allocation is now transactional: missing sparse pages are allocated into temporary buffers before any are installed or image words are copied. Allocation failure returns the documented loader error rather than taking the emulator's non-program machine-fault exit. A test-only allocator fault forces this failure and confirms the target page remains absent and unchanged. Suite: CPU 187, OS/compiler 1,746, native console 28.
Nested trap-6 audit found that a rejected recursive run cleared `application32` while the outer native app kept running. The trap now returns `-1` before changing execution mode. A CPU fixture executes nested trap 6, then stores to valid high app memory and exits successfully. Suite: CPU 187, OS/compiler 1,746, console 28.
The expanded bob32 kernel overlapped the legacy program region at `0x9000`. The bob32 OS now loads kind-1 legacy apps at `0xB000..0xBFFF`, leaves the 16-bit bob16 location unchanged, and rejects a legacy run if the active B32 kernel occupies that window. This also removes the old post-run image restore that reset RAM filesystem metadata. Snapshot descriptor validation now allows B32 kernel tables below `0xB000` while retaining the old bob16 ceiling. CPU fixtures run a 16-bit `LEA/PUTS/HALT` program and reject a low legacy entry; OS integration checks `bob!`/exit 33, file listing after execution, and snapshot save/restore. Suite: CPU 189, OS/compiler 1,746, console 28.
Resident B32 functions now use per-call stack frames, parameter offsets, local slots, forward-call patch chains, and a common return epilogue. The shell regression calls a later-defined no-argument function as a statement, calls a two-argument function for its value, and computes factorial recursively; it prints `bob!` and returns 0. The test runner counts all nine successful B32 shell programs. Suite: CPU 189, OS/compiler 1,746, console 28.
Resident B32 frame-offset audit found that local slot numbers were masked to six bits when encoded in LDR/STR instructions. A sufficiently large function with many sequential inner-scope declarations could silently access the wrong stack word after slot 32. The compiler now rejects a 33rd local slot, and a shell regression generates 33 block-scoped declarations to verify rejection. B32 kernel rebuild: 43,113 words; OS/compiler suite: 1,749 checks passed.
The B32 kernel had only 70 words of headroom before the legacy-app region after adding local arrays. Since RAM files are limited to 511 words, the kind-1 B32 legacy window moved to `0xB800..0xBFFF` and was reduced to 2,048 reserved words, still leaving over three times the largest file size. The emulator's entry/store/GETS bounds, OS program loading, snapshot table ceiling, direct CPU fixture and memory-map docs now agree. The kernel ends at `0xAFBA`, leaving 2,118 words before the B32 legacy window. CPU boundary fixtures verify writes at `0xB800` and rejection below it. Full suites: CPU 191, OS/compiler 1,752, console 28.
Resident bob32 local arrays are fixed-size, one-dimensional `int` objects within the 32-slot frame budget. The compiler zero-initializes elements, emits indexed loads, and supports indexed assignment statements. A shell regression fills and sums an array in loops and verifies `bob!`/exit 0. At that stage array parameters, explicit initializers, multidimensional arrays and bob16 resident arrays remained unsupported. Full suites: CPU 191, OS/compiler 1,752, console 28.
Indexed bob32 array statements now also support postfix increment/decrement and compound assignments, including shifts implemented through helper calls. The regression increments element zero, adds to element one and shifts element two before summing. The B32 kernel is 44,833 words, ending at `0xB221` with 1,503 words before the `0xB800` legacy-app region. Full suites: CPU 191, OS/compiler 1,752, console 28.
Fixed-size bob32 local arrays now accept brace initializer lists containing scalar expressions and an optional trailing comma. Omitted elements retain the zero fill emitted for automatic arrays; an excess element triggers a compile error. The shell fixture validates explicit values and zero-filled tail elements before exercising indexed mutation, then confirms an oversized initializer is rejected. The rebuilt B32 kernel is 45,070 words and ends at `0xB30E`, leaving 1,266 words before the legacy-app region. OS/compiler suite: 1,753 checks passed.
Indexed bob32 array prefix/postfix increment and decrement now work inside expressions. The generated code preserves the old value for postfix, stores the updated element, then returns the old value; prefix returns the new value. A separate compiled app verifies both value rules at runtime. It is kept separate from the larger array loop test so both remain below the 511-word RAM-file cap. The kernel is 45,299 words, ending at `0xB3F3` with 1,037 words before the legacy window. OS/compiler suite: 1,754 checks passed.
The bob32 resident parser now accepts comma-separated local scalar and fixed-array declarators, each with its own initializer. Runtime coverage combines an initialized array and scalar, and initializes a scalar from an array postfix expression in the same declaration. The 45,331-word kernel ends at `0xB413`, leaving 1,005 words before the `0xB800` legacy window. OS/compiler suite: 1,754 checks passed.
The bob32 resident parser now accepts `int` function prototypes with named or unnamed integer parameters, permits unused declarations without definitions, and checks prototype/definition and prototype/call argument counts. A shell integration compiles a prototype-before-definition call and an unused unnamed-parameter declaration, runs it, and rejects conflicting prototypes. The 45,486-word kernel ends at `0xB4AE`, leaving 850 words before the `0xB800` legacy window. OS/compiler suite: 1,758 checks passed.
Resident bob32 C now supports local function pointers returning `int` and accepting integer arguments. A pointer can be initialized from a function declared by prototype and called indirectly; the integration fixture checks the result, `bob!` output and exit code. The kind-1 compatibility window moved to `0xBA00..0xBFFF` because the kernel reached 46,733 words (`0xB98D` end), leaving 115 words for growth. Emulator bounds, guest loader, storage limit, CPU fixtures and memory-map docs were updated together. Suites: CPU 191, OS/compiler 1,761, console 28.
Function-pointer initialization and assignment now require a previously declared function with a matching argument count; compatible local function pointers can be copied, and null `0` is supported. Mismatched signatures and integer values are rejected. Kernel growth required moving bob32 compatibility apps to `0xC000..0xCFFF` and the B32 heap to `0xD000..0xDFFF`; bob16 applications move to `0xA000` so its enlarged kernel still fits, with only its dedicated `0x9800..0x980F` compiler-variable area additionally writable by supervised apps. B16 image limits, storage descriptor checks, shell heap bounds, docs and CPU/OS regressions were aligned. Current images: B16 36,325 words (ends `0x90E4`); B32 48,185 words (ends `0xBF38`). Suites: CPU 194, OS/compiler 1,764; console: 28 checks passed.
Resident bob32 now distinguishes `int f()` from the zero-argument prototype `int f(void)`. A no-prototype declaration can be refined by a typed declaration or later definition; calls before that definition are checked against its eventual parameter count to preserve this calling convention. End-to-end tests cover a valid call through `int loose()` and rejection when a one-argument call precedes a two-argument definition. B32 image: 48,185 words, ending at `0xBF38` with 199 words before the compatibility window. Full suites: CPU 194, OS/compiler 1,764, console 28.
The bob32 resident compiler now recognizes `print`, `println`, `print_dec` and `print_hex` as kernel functions without requiring source prototypes. A regression runs `write bobs.c int main(void){println("Bob!");return 0;}` followed by `go bobs.c` and verifies `Bob!` with exit status 0. This kernel growth moves the bob32 compatibility-app window to `0xC200..0xCFFF`; the emulator protects that window from writes below it. Current B32 image: 48,645 words, ending at `0xC164`.
The bob32 resident compiler now stages generated code at the native application origin and can save output up to the available packed filesystem capacity; bob16 retains its 511-word code limit. A shell integration compiles a compact source into a 1,289-word resident app, runs it to print `bob!`, snapshots the filesystem, restores the snapshot, and runs the stored app again. Full suites: CPU 203, OS/compiler 1,822, console 28.
The bob32 resident compiler now adjusts one-dimensional `int values[]` (and fixed-bound parameter spellings) to a single word-addressed pointer argument using the existing stack ABI. Helpers can index and mutate caller arrays, forward an array to nested helper calls, and combine it with scalar parameters. Regression coverage computes a sum, increments elements in a second helper, calls the sum helper repeatedly, and prints `bob!`; negative cases reject scalar/array argument mismatches, conflicting prototypes, and multidimensional parameter syntax. Full suites: CPU 203, OS/compiler 1,825, console 28.
Added app-side `bob_string.h` helpers for length/copy/compare/concatenate/search, whitespace checks, signed decimal and hexadecimal parsing with overflow reporting, integer formatting with capacity checks, and in-place quoted command tokenization. A bob32 runtime fixture covers integer limits, malformed input, quoting and escapes; a compact native app imports into bob32 RAM files, prints `bob!`, survives a B32S snapshot restore, and runs again. Full suites: CPU 203, OS/compiler 1,840, console 28.
The host-compiled C workflow now includes `<stdbool.h>` backed by the tested `_Bool` type. B16 and B32 guest fixtures verify `bool`, `true` and `false` at runtime and print `bob!`. GCC `-fanalyzer` reported no diagnostics in the emulator, compiler or test sources. At this point suites were CPU 194, OS/compiler 1,769, console 28.
Added `<stddef.h>` with width-matched `size_t`/`ptrdiff_t` and `NULL`. `sizeof` now has unsigned type in expression and type-name forms. Native B16/B32 fixtures verify array size, pointer subtraction, null initialization and unsigned `sizeof` arithmetic. Full suite: CPU 194, OS/compiler 1,773, console 28.
Host C now supports typed function-pointer declarations and calls, including local/file-scope pointers, nested pointer parameters, function-address relocations, copying, and parenthesized indirect calls. Empty `()` signatures accept unspecified call arguments; typed signatures enforce argument count and compatibility. B16/B32 positive and negative regressions cover these behaviors, including invalid casts between function and object pointers. Full suite: CPU 194, OS/compiler 1,793, console 28.
Native bob32 application workflow: the RAM filesystem packs eight file slots into 4,096 words, allowing validated B32K v2 images larger than 511 words. `import32 HOST_PATH NAME` stores an image, `run NAME` or `run32 NAME` executes it from guest RAM, and B32S v2 snapshots preserve it; B32S v1 fixed-slot snapshots convert on restore. Integration tests import a 629-word image, execute it through both guest-name commands, save/restore, and execute again. Failure coverage checks missing, invalid and truncated images, storage-capacity exhaustion, checksum corruption and sparse-memory allocation failure. The expanded bob32 kernel now runs at `0x10000..0x1D115`, with native applications starting at `0x20000`. Resident compiler diagnostics include token context with the existing source location. Full suite: CPU 203, OS/compiler 1,813, console 28.
+380
View File
@@ -0,0 +1,380 @@
/* CPU migration checks; include the real implementation rather than a model. */
#ifndef _WIN32
#define _POSIX_C_SOURCE 200809L
#endif
#define BOB_TESTING
#define main bob_emulator_main
#include "../main.c"
#undef main
#include <limits.h>
#define TEST_APP_BASE 0x20000u
static int checks;
static int storage_path(const char *path) {
#ifdef _WIN32
return _putenv_s("BOB16_STORAGE",path);
#else
return *path?setenv("BOB16_STORAGE",path,1):unsetenv("BOB16_STORAGE");
#endif
}
static void verify(int okay,const char *what) {
checks++;if(!okay){fprintf(stderr,"CPU check failed: %s\n",what);exit(1);}
}
static void reset_cpu(int wide) {memoryReset();memset(&cpu,0,sizeof(cpu));memset(&ram,0,sizeof(ram));cpu32=wide;programMode=false;application32=false;legacyProgram32=false;}
static void step(unsigned instruction) {ram.memory[cpu.pc]=instruction;cpuCycle();}
static void put16(FILE *f,unsigned value) {fputc(value&255,f);fputc((value>>8)&255,f);}
static void put32(FILE *f,uint32_t value) {put16(f,value);put16(f,value>>16);}
static int assembly_text(const char *text) {
FILE *f=tmpfile();if(!f)exit(1);fputs(text,f);rewind(f);
reset_cpu(0);int result=assembleSource(f);fclose(f);return result;
}
static int assembly_bytes(const unsigned char *data,size_t length) {
FILE *f=tmpfile();if(!f)exit(1);
if(fwrite(data,1,length,f)!=length){fclose(f);exit(1);}
rewind(f);reset_cpu(0);int result=assembleSource(f);fclose(f);return result;
}
static void bad_image(const char *executable,const unsigned char *bytes,size_t length) {
FILE *f=fopen("build/cpu-bad.b32","wb");if(!f)exit(1);
if(fwrite(bytes,1,length,f)!=length || fclose(f))exit(1);
char command[4096];snprintf(command,sizeof(command),"\"%s\" --load-fixture build/cpu-bad.b32 > build/cpu-bad.out 2>&1",executable);
verify(system(command)!=0,"invalid wide image rejected");
}
int main(int argc,char **argv) {
if(argc>1 && !strcmp(argv[1],"--emulator"))return bob_emulator_main(argc-1,argv+1);
if(argc==3 && !strcmp(argv[1],"--load-fixture")){bootImage(argv[2]);return 0;}
if(argc==3 && !strcmp(argv[1],"--disk-argument-fixture")) {
int argument=argv[2][0]-'0';if(argument<0 || argument>2)return 2;
reset_cpu(1);bootMode=true;bootWords=1;bootDisk[0]=42;
cpu.regFile[0]=argument==0?0x10000:0x300;cpu.regFile[1]=0;cpu.regFile[2]=1;
cpu.regFile[argument]|=0x10000;step(0xf400);
return argument==0 && memoryRead(0x10000)!=42?1:0;
}
if(argc==2 && !strcmp(argv[1],"--puts-fixture")) {
reset_cpu(1);cpu.regFile[0]=0x10000;
memoryWrite(0x10000,0x10000);memoryWrite(0x10001,'b');memoryWrite(0x10002,'o');
memoryWrite(0x10003,'b');memoryWrite(0x10004,'!');step(0xf200);
return cpu.ir==0xf200?0:1;
}
for(unsigned bits=1;bits<=16;bits++) {
verify(sext((int16_t)((1u<<bits)-1),bits)==-1,"negative immediate");
verify(sext((int16_t)((1u<<(bits-1))-1),bits)==(int)((1u<<(bits-1))-1),"positive immediate");
}
unsigned long limit=123;
const char *invalid_limits[]={"","0","-1","+1"," 1","1 ","1x","999999999999999999999999999999999999999999"};
for(unsigned i=0;i<sizeof(invalid_limits)/sizeof(invalid_limits[0]);i++) {
verify(!parseCycleLimit(invalid_limits[i],&limit) && limit==123,"invalid cycle limit leaves output intact");
}
verify(parseCycleLimit("1",&limit) && limit==1,"minimum cycle limit");
char maximum[64];snprintf(maximum,sizeof(maximum),"%lu",ULONG_MAX);
verify(parseCycleLimit(maximum,&limit) && limit==ULONG_MAX,"maximum cycle limit");
reset_cpu(0);verify(snapshotService(UINT_MAX,1)==-3,"snapshot descriptor rejects unsigned overflow");
verify(snapshotService(0xf000-3,1)==-3,"snapshot descriptor end bound");
reset_cpu(1);
ram.memory[0x300]=0x400;ram.memory[0x301]=0x500;ram.memory[0x302]=0x510;ram.memory[0x303]=0x520;
ram.memory[0x300]=0x1000400;
verify(snapshotService(0x300,0)==-3,"wide snapshot rejects truncated address in descriptor");
ram.memory[0x300]=0x400;
cpu.regFile[0]=0x1000300;cpu.regFile[1]=0;step(0xf700);
verify(cpu.regFile[0]==-3,"wide storage trap rejects truncated descriptor address");
ram.memory[0x400]='b';ram.memory[0x401]='o';ram.memory[0x402]='b';ram.memory[0x403]='!';
ram.memory[0x500]=1;ram.memory[0x510]=1;ram.memory[0x520]=1;ram.memory[0xf000]=0x12345678;ram.memory[0xf001]=0;
const char *source_name="bobs.c",*source_text="bob!";
for(unsigned i=0;source_name[i];i++)ram.memory[0x418+i]=source_name[i];
ram.memory[0x501]=4;ram.memory[0x521]=1;
for(unsigned i=0;source_text[i];i++)ram.memory[0xf002+i]=source_text[i];
ram.memory[0xf006]=0;
if(storage_path("build/cpu-snapshot.b32"))return 1;
verify(snapshotService(0x300,0)==0,"wide snapshot save");
ram.memory[0xf000]=0;
verify(snapshotService(0x300,1)==0 && ram.memory[0xf000]==0x12345678,"wide snapshot restores all 32 bits");
FILE *saved=fopen("build/cpu-snapshot.b32","r+b");if(!saved)return 1;
if(fseek(saved,16+216*4+3,SEEK_SET))return 1;
if(fputc(0x13,saved)==EOF || fclose(saved))return 1;
ram.memory[0xf000]=42;
verify(snapshotService(0x300,1)==-2 && ram.memory[0xf000]==42,"wide snapshot checksum protects upper byte and RAM");
ram.memory[0xf000]=0x12345678;
verify(snapshotService(0x300,0)==0,"wide snapshot resave");
FILE *old_snapshot=fopen("build/cpu-snapshot.b32","r+b");if(!old_snapshot)return 1;
uint32_t old_words[SNAP_WORDS];if(fseek(old_snapshot,16,SEEK_SET))return 1;
for(unsigned i=0;i<SNAP_WORDS;i++){unsigned char b[4];if(fread(b,1,4,old_snapshot)!=4)return 1;old_words[i]=(uint32_t)b[0]|((uint32_t)b[1]<<8)|((uint32_t)b[2]<<16)|((uint32_t)b[3]<<24);}
for(unsigned i=0;i<=4;i++)old_words[216+512+i]=old_words[218+i];
uint32_t old_hash=snapshotHash(old_words,SNAP_WORDS);if(fseek(old_snapshot,4,SEEK_SET)||fputc(1,old_snapshot)==EOF||fseek(old_snapshot,12,SEEK_SET))return 1;
for(unsigned i=0;i<4;i++)if(fputc((old_hash>>(8*i))&255,old_snapshot)==EOF)return 1;
if(fseek(old_snapshot,16,SEEK_SET))return 1;
for(unsigned i=0;i<SNAP_WORDS;i++)for(unsigned b=0;b<4;b++)if(fputc((old_words[i]>>(8*b))&255,old_snapshot)==EOF)return 1;
if(fclose(old_snapshot))return 1;
ram.memory[0xf000]=0;ram.memory[0xf002]=0;
verify(snapshotService(0x300,1)==0 && ram.memory[0xf000]==0x12345678 && ram.memory[0xf002]=='b',"legacy fixed-slot B32S snapshot converts to packed filesystem layout");
cpu32=false;ram.memory[0xf000]=42;
verify(snapshotService(0x300,1)==-2 && ram.memory[0xf000]==42,"legacy rejects wide snapshot without modifying RAM");
cpu32=true;kernelIdentity++;
verify(snapshotService(0x300,1)==1,"wide snapshot reports changed kernel identity");
verify(ram.memory[0x520]==0 && ram.memory[0x521]==1 && ram.memory[0xf000]=='b' && ram.memory[0xf003]=='!',"wide kernel change drops binaries and preserves text");
kernelIdentity--;
if(storage_path(""))return 1;
uint32_t snapshot[SNAP_WORDS]={0};
verify(snapshotValid(snapshot),"empty snapshot metadata");
snapshot[0]='b';snapshot[1]='o';snapshot[2]='b';snapshot[3]='!';snapshot[192]=4;snapshot[208]=1;
snapshot[216]='b';snapshot[217]='o';snapshot[218]='b';snapshot[219]='!';
verify(snapshotValid(snapshot),"valid text snapshot metadata");
snapshot[218]=0;verify(!snapshotValid(snapshot),"text snapshot rejects embedded terminator");snapshot[218]='b';
snapshot[220]=1;verify(!snapshotValid(snapshot),"snapshot rejects missing content terminator");snapshot[220]=0;
snapshot[192]=512;verify(!snapshotValid(snapshot),"snapshot rejects excessive length");snapshot[192]=4;
snapshot[208]=2;verify(!snapshotValid(snapshot),"snapshot rejects invalid used flag");snapshot[208]=1;
snapshot[200]=2;verify(snapshotValid(snapshot),"bob32 snapshots accept native program files");
snapshot[200]=4;verify(!snapshotValid(snapshot),"snapshot rejects invalid kind");snapshot[200]=0;
memcpy(snapshot+24,snapshot,24*sizeof(uint32_t));snapshot[209]=1;
verify(!snapshotValid(snapshot),"snapshot rejects duplicate names");snapshot[209]=0;
verify(assembly_text(".stringz bob!\n.fill 1234\n")==0 && ram.memory[4]==0 && ram.memory[5]==0x1234,"string directive emits exactly one terminator");
verify(assembly_text("add r0 r1 r2\r\n.fill ffff\r\n")==0 && ram.memory[1]==0xffff,"CRLF token separation");
verify(assembly_text(".fill ffffg\n")<0,"fill rejects trailing text");
const unsigned char embedded_nul[]={'.','f','i','l','l',' ','1',0,' ','x','\n'};
verify(assembly_bytes(embedded_nul,sizeof(embedded_nul))<0,"assembly rejects embedded zero byte");
verify(assembly_text(".fill 10000\n")<0,"fill rejects truncation");
verify(assembly_text(".fill -1\n")<0,"fill rejects signed text");
verify(assembly_text("nop\n.fill 1234\n")==0 && ram.memory[0]==0 && ram.memory[1]==0x1234,"documented nop assembles");
verify(assembly_text("nop r0\n")<0,"nop rejects operands");
char boundary_source[300];memset(boundary_source,' ',252);strcpy(boundary_source+252,"nop\r\n.fill 1234\n");
verify(assembly_text(boundary_source)==0 && ram.memory[0]==0 && ram.memory[1]==0x1234,"exact-limit CRLF source line keeps following instruction");
memset(boundary_source,' ',253);strcpy(boundary_source+253,"nop\r\n.fill 1234\n");
verify(assembly_text(boundary_source)<0,"source line over the limit remains rejected");
const char *bad_operands[]={"add r0 r1 r8\n","add r0 bogus\n","and r0 r1 1x\n","and r0 r9\n",
"not r0 r8\n","not r0 r1 ignored\n","not\n","ld r0 bogus\n","ld r8 0\n","ld xx 0\n",
"ldi r8 0\n","ldr r0 r8 0\n","ldr r8 r0 0\n","ldr r0 r1 --1\n",
"st r8 0\n","st xx 0\n","st r0 1x\n","sti r8 0\n","sti r0 bogus\n",
"str r8 r0 0\n","str r0 r8 0\n","str r0 r1 r8\n","br np 1x\n","jsr bogus\n","lea r0 bogus\n",
"trap nonsense\n","trap 12\n","trap 15\n",
"br nx 1\n","add r0 999999999999999999999\n"};
for(unsigned i=0;i<sizeof(bad_operands)/sizeof(bad_operands[0]);i++)verify(assembly_text(bad_operands[i])<0,"invalid instruction operand rejected");
verify(assembly_text("add r0 100\nadd r0 -100\njsr -1\njsrr r3\n")==0 && ram.memory[0]==0x11bf && ram.memory[1]==0x11c0 && ram.memory[2]==0xcfff && ram.memory[3]==0xc300,"decimal clamping and call encodings preserved");
int immediate=7;
verify(parseImmediate("+123",&immediate) && immediate==123,"signed decimal operand");
verify(!parseImmediate("-",&immediate) && immediate==123,"missing digits reject without modifying result");
char oversized[300];memset(oversized,' ',sizeof(oversized));memcpy(oversized,".fill 1",7);oversized[298]='\n';oversized[299]=0;
verify(assembly_text(oversized)<0,"oversized physical line rejects before splitting");
FILE *full=tmpfile();if(!full)return 1;
for(unsigned i=0;i<65536;i++)fputs(".fill 0\n",full);
rewind(full);reset_cpu(0);verify(assembleSource(full)==0,"full address-space assembly fits exactly");fclose(full);
full=tmpfile();if(!full)return 1;
for(unsigned i=0;i<65535;i++)fputs(".fill 0\n",full);
fputs(".stringz bob!\n",full);rewind(full);reset_cpu(0);
verify(assembleSource(full)==-7 && ram.memory[65535]==0,"oversized string rejected before writing");fclose(full);
reset_cpu(0);cpu.regFile[0]=32767;step(0x1181);
verify(cpu.regFile[0]==-32768 && cpu.cc[N],"bob16 wrap and negative flag");
reset_cpu(1);cpu.regFile[0]=32767;step(0x1181);
verify(cpu.regFile[0]==32768 && cpu.cc[P],"bob32 crosses 16-bit boundary");
cpu.regFile[0]=INT32_MAX;step(0x1181);
verify(cpu.regFile[0]==INT32_MIN && cpu.cc[N],"bob32 wraps at 32 bits");
cpu.regFile[0]=-1;step(0x1181);
verify(cpu.regFile[0]==0 && cpu.cc[Z],"32-bit zero flag");
cpu.regFile[0]=0x12345678;cpu.regFile[1]=100;step(0x9040);
verify(ram.memory[100]==0x12345678,"wide store");step(0x6440);
verify(cpu.regFile[2]==0x12345678,"wide load");
reset_cpu(0);cpu.pc=0x8000;step(0xc800);
verify(cpu.regFile[7]==(int16_t)0x8001,"legacy signed return-address register");
reset_cpu(1);cpu.pc=0x8000;step(0xc800);
verify(cpu.regFile[7]==0x8001,"wide return-address register");
reset_cpu(1);memoryWrite(TEST_APP_BASE,0x4001);memoryWrite(TEST_APP_BASE+1,0xe000);memoryWrite(TEST_APP_BASE+2,0x12345678);
cpu.regFile[0]=TEST_APP_BASE;step(0xf600);
verify(cpu.regFile[0]==0x12345678 && cpu.pc==1 && !programMode,"wide supervised return and parent restoration");
reset_cpu(1);memoryWrite(TEST_APP_BASE,0x1000f000);application32=1;
cpu.regFile[2]=42;
verify(runProgram(TEST_APP_BASE)==-2 && cpu.regFile[2]==42 && cpu.pc==0 && !programMode,"wide instruction upper bits fault and restore parent");
application32=0;
reset_cpu(0);ram.memory[0xa000]=(int16_t)0xe000;
verify(runProgram(0xa000)==0,"legacy signed instruction representation remains valid");
reset_cpu(0);memoryWrite(0xa000,0x9200);memoryWrite(0xa001,0xf000);cpu.regFile[0]=0x9800;cpu.regFile[1]=42;
verify(runProgram(0xa000)==0x9800 && memoryRead(0x9800)==42,"bob16 applications retain access to resident compiler variable slots");
reset_cpu(0);memoryWrite(0xa000,0x9200);memoryWrite(0xa001,0xf000);cpu.regFile[0]=0x9810;cpu.regFile[1]=42;
verify(runProgram(0xa000)==-2 && memoryRead(0x9810)!=42,"bob16 applications cannot write kernel memory around compiler slots");
const unsigned malformed[]={0x0001,0x1001,0x2001,0x3120,0xc001,0xe001};
reset_cpu(1);cpu.regFile[0]=0x1009000;cpu.regFile[2]=42;memoryWrite(0x10000,0xf600);cpu.pc=0x10000;cpuCycle();
verify(cpu.regFile[0]==-2 && cpu.regFile[2]==42 && !programMode,"wide run trap rejects truncated entry address");
for(unsigned argument=1;argument<2;argument++) {
reset_cpu(1);memoryWrite(TEST_APP_BASE,0xf300);memoryWrite(TEST_APP_BASE+1,0xe000);memoryWrite(0x10010,77);application32=1;
cpu.regFile[0]=0x10010;cpu.regFile[1]=2;cpu.regFile[argument]|=0x10000;
verify(runProgram(TEST_APP_BASE)==-2 && memoryRead(0x10010)==77 && !programMode,"wide input trap rejects truncated arguments before writing");
application32=0;
}
reset_cpu(1);memoryWrite(TEST_APP_BASE,0xf300);memoryWrite(TEST_APP_BASE+1,0xf000);application32=1;
cpu.regFile[0]=TEST_APP_BASE;cpu.regFile[1]=2;
int input_status=runProgram(TEST_APP_BASE);
verify(input_status==TEST_APP_BASE && memoryRead(TEST_APP_BASE)==0,"wide input trap writes to full-width guest address");
application32=0;
reset_cpu(1);cpu.regFile[0]=0x10000;step(0xb000);
verify(cpu.pc==0x10000,"wide JMP preserves 32-bit address");
reset_cpu(1);cpu.regFile[0]=0x10000;step(0xc000);
verify(cpu.pc==0x10000 && cpu.regFile[7]==1,"wide JSRR preserves 32-bit address");
reset_cpu(1);cpu.regFile[7]=0x10000;step(0xe000);
verify(cpu.pc==0x10000,"wide RET preserves 32-bit address");
reset_cpu(1);cpu.regFile[0]=0x12345000;cpu.regFile[1]=0x12345678;step(0x9200);
verify(memoryRead(0x12345000)==0x12345678,"wide STR writes above 64K words");
step(0x6400);verify(cpu.regFile[2]==0x12345678,"wide LDR reads above 64K words");
reset_cpu(1);memoryWrite(0x10000,0x12345678);memoryWrite(0x10100,0x5400);memoryWrite(0x10101,0x10000);
cpu.pc=0x10100;cpuCycle();verify(cpu.regFile[2]==0x12345678,"wide LDI follows full-width pointer");
memoryWrite(0x10200,0x8200);memoryWrite(0x10201,0x10000);cpu.regFile[1]=0x87654321;cpu.pc=0x10200;cpuCycle();
verify(memoryRead(0x10000)==(int32_t)0x87654321u,"wide STI follows full-width pointer");
reset_cpu(1);memoryWrite(TEST_APP_BASE,0x9200);memoryWrite(TEST_APP_BASE+1,0x6400);
memoryWrite(TEST_APP_BASE+2,0x10a0);memoryWrite(TEST_APP_BASE+3,0xf000);
cpu.regFile[0]=0x22345;cpu.regFile[1]=0x12345678;
application32=1;
verify(runProgram(TEST_APP_BASE)==0x12345678 && memoryRead(0x22345)==0x12345678,
"supervised bob32 program reads and writes full-width data addresses");
reset_cpu(1);memoryWrite(TEST_APP_BASE,0xf600);memoryWrite(TEST_APP_BASE+1,0x400e);
memoryWrite(TEST_APP_BASE+2,0x9200);memoryWrite(TEST_APP_BASE+3,0xf000);
memoryWrite(TEST_APP_BASE+0x10,TEST_APP_BASE+0x20);cpu.regFile[0]=TEST_APP_BASE;cpu.regFile[1]=42;application32=1;
int nested_status=runProgram(TEST_APP_BASE);
verify(nested_status==TEST_APP_BASE+0x20 && memoryRead(TEST_APP_BASE+0x20)==42,
"rejected nested run leaves native application memory mode intact");
application32=0;
reset_cpu(1);memoryWrite(TEST_APP_BASE,0x9200);memoryWrite(TEST_APP_BASE+1,0xf000);
cpu.regFile[0]=0xfffff;cpu.regFile[1]=0x12345678;application32=1;
verify(runProgram(TEST_APP_BASE)==0xfffff && memoryRead(0xfffff)==0x12345678,
"supervised bob32 program may write the last word in its region");
const uint32_t forbidden_app_addresses[]={0xffff,0x10000,0x1ffff,0x100000,0x110000,0x12345000,UINT32_MAX};
for(unsigned i=0;i<sizeof(forbidden_app_addresses)/sizeof(forbidden_app_addresses[0]);i++) {
reset_cpu(1);memoryWrite(TEST_APP_BASE,0x9200);memoryWrite(TEST_APP_BASE+1,0xf000);
cpu.regFile[0]=(int32_t)forbidden_app_addresses[i];cpu.regFile[1]=0x76543210;application32=1;
verify(runProgram(TEST_APP_BASE)==-2 && memoryRead(forbidden_app_addresses[i])!=0x76543210,
"supervised bob32 store rejects addresses outside app and stack region");
}
application32=0;
reset_cpu(1);bootWideHeader=false;bootOrigin=0;bootWords=0;memoryWrite(0xc200,0xd002);memoryWrite(0xc201,0xf200);memoryWrite(0xc202,0xf000);
memoryWrite(0xc203,'b');memoryWrite(0xc204,'o');memoryWrite(0xc205,'b');memoryWrite(0xc206,'!');memoryWrite(0xc207,0);
verify(runProgram(0xc200)==33 && !programMode,"bob32 kernel runs a legacy 16-bit program outside its image");
verify(runProgram(0x9000)==-1 && runProgram(0xb000)==-1 && runProgram(0xb800)==-1,"bob32 kernel rejects legacy entries that overlap kernel image or reserved gap");
reset_cpu(1);bootWideHeader=false;bootOrigin=0;bootWords=0;memoryWrite(0xc200,0x9200);memoryWrite(0xc201,0xf000);
cpu.regFile[0]=0xc200;cpu.regFile[1]=0x1234;
verify(runProgram(0xc200)==0xc200 && memoryRead(0xc200)==0x1234,"bob32 legacy app may store at the first reserved program word");
reset_cpu(1);memoryWrite(0xc200,0x9200);memoryWrite(0xc201,0xf000);cpu.regFile[0]=0xc1ff;cpu.regFile[1]=0x5678;
verify(runProgram(0xc200)==-2 && memoryRead(0xc1ff)!=0x5678,"bob32 legacy app cannot write below its relocated region");
reset_cpu(1);memoryWrite(0xc200,0x9200);memoryWrite(0xc201,0xf000);cpu.regFile[0]=0xd000;cpu.regFile[1]=0x5678;
verify(runProgram(0xc200)==0xd000 && memoryRead(0xd000)==0x5678,"bob32 legacy app retains shared heap data access");
reset_cpu(0);cpu.regFile[0]=0x10000;cpu.regFile[1]=42;step(0x9200);
verify(ram.memory[0]==42,"legacy STR retains 16-bit address wrapping");
for(unsigned wide=0;wide<2;wide++)for(unsigned i=0;i<sizeof(malformed)/sizeof(malformed[0]);i++) {
reset_cpu(wide);if(wide)application32=1;cpu.regFile[2]=42;uint32_t entry=wide?TEST_APP_BASE:0xa000;memoryWrite(entry,wordValue(malformed[i]));
verify(runProgram(entry)==-2 && cpu.regFile[2]==42 && cpu.pc==0 && !programMode,"reserved instruction bits fault and restore parent");
application32=0;
}
char command[4096];
snprintf(command,sizeof(command),"\"%s\" --disk-argument-fixture 0 > build/cpu-disk-argument.out 2>&1",argv[0]);
verify(system(command)==0,"wide boot disk trap writes to full-width destination");
for(unsigned argument=1;argument<3;argument++) {
snprintf(command,sizeof(command),"\"%s\" --disk-argument-fixture %u > build/cpu-disk-argument.out 2>&1",argv[0],argument);
verify(system(command)!=0,"wide boot disk trap rejects truncated arguments");
FILE *fault=fopen("build/cpu-disk-argument.out","rb");if(!fault)return 1;
char diagnostic[256];size_t used=fread(diagnostic,1,sizeof(diagnostic)-1,fault);fclose(fault);diagnostic[used]=0;
verify(strstr(diagnostic,"Invalid boot disk argument")!=NULL,"disk argument fixture reaches the intended trap fault");
}
snprintf(command,sizeof(command),"\"%s\" --puts-fixture > build/cpu-puts.out",argv[0]);
verify(system(command)==0,"wide string trap preserves instruction state");
FILE *output=fopen("build/cpu-puts.out","rb");if(!output)return 1;
unsigned char bytes[7];size_t length=fread(bytes,1,sizeof(bytes),output);fclose(output);
#ifdef _WIN32
verify(length==7 && !memcmp(bytes,"\0bob!\r\n",7),"wide string terminator compares entire word");
#else
verify(length==6 && !memcmp(bytes,"\0bob!\n",6),"wide string terminator compares entire word");
#endif
FILE *f=fopen("build/cpu-wide.b32","wb");if(!f)return 1;
uint32_t words[]={0x4001,0,0x12345678};unsigned sum=0;
for(unsigned i=0;i<3;i++)sum+=words[i];
fwrite("B32K",1,4,f);put16(f,1);put16(f,0x300);put16(f,0x300);put16(f,3);put16(f,sum);put16(f,sum>>16);
for(unsigned i=0;i<3;i++){put16(f,words[i]);put16(f,words[i]>>16);}fclose(f);
unsigned char image[29];f=fopen("build/cpu-wide.b32","rb");if(!f)return 1;
verify(fread(image,1,28,f)==28,"wide fixture length");fclose(f);
bad_image(argv[0],image,14);bad_image(argv[0],image,27);
image[12]^=1;bad_image(argv[0],image,28);image[12]^=1;
image[28]=0;bad_image(argv[0],image,29);
unsigned char entry=image[8];image[8]=0xff;image[9]=0xff;bad_image(argv[0],image,28);image[8]=entry;image[9]=3;
image[4]=2;bad_image(argv[0],image,28);image[4]=1;
bootImage("build/cpu-wide.b32");
verify(cpu32 && bootDisk[2]==0x12345678,"wide image loader");
for(unsigned i=0;i<6;i++)cpuCycle();
verify(cpu.pc==0x300 && ram.memory[0x302]==0x12345678,"wide guest boot disk transfer");
cpuCycle();verify(cpu.regFile[0]==0x12345678,"wide image native execution");
f=fopen("build/cpu-wide-v2.b32","wb");if(!f)return 1;
uint32_t wide_words[]={0x1080,0x12345678};uint32_t wide_sum=wide_words[0]+wide_words[1];
fwrite("B32K",1,4,f);put16(f,2);put16(f,24);put32(f,0x10000);put32(f,0x10000);
put32(f,2);put32(f,wide_sum);put32(f,wide_words[0]);put32(f,wide_words[1]);fclose(f);
bootImage("build/cpu-wide-v2.b32");
verify(cpu32 && cpu.pc==0x10000 && memoryRead(0x10001)==0x12345678,"B32K v2 loads at a 32-bit origin and entry");
cpuCycle();verify(cpu.pc==0x10001 && cpu.regFile[0]==0,"B32K v2 executes at a high address");
unsigned char v2_image[33];f=fopen("build/cpu-wide-v2.b32","rb");if(!f)return 1;
verify(fread(v2_image,1,32,f)==32,"B32K v2 fixture length");fclose(f);v2_image[32]=0;
bad_image(argv[0],v2_image,23);
v2_image[4]=3;bad_image(argv[0],v2_image,32);v2_image[4]=2;
v2_image[6]=22;bad_image(argv[0],v2_image,32);v2_image[6]=24;
for(unsigned i=8;i<16;i++)v2_image[i]=0xff;
bad_image(argv[0],v2_image,32);
v2_image[8]=0;v2_image[9]=0;v2_image[10]=1;v2_image[11]=0;
v2_image[12]=0;v2_image[13]=0;v2_image[14]=1;v2_image[15]=0;
v2_image[12]=0;v2_image[13]=0;v2_image[14]=2;v2_image[15]=0;bad_image(argv[0],v2_image,32);v2_image[12]=0;v2_image[13]=0;v2_image[14]=1;v2_image[15]=0;
v2_image[16]=1;v2_image[17]=0;v2_image[18]=1;v2_image[19]=0;bad_image(argv[0],v2_image,32);v2_image[16]=2;v2_image[17]=0;v2_image[18]=0;v2_image[19]=0;
v2_image[31]^=1;bad_image(argv[0],v2_image,32);v2_image[31]^=1;
bad_image(argv[0],v2_image,33);
for(unsigned i=8;i<16;i++)v2_image[i]=0xff;
v2_image[8]=0xfe;v2_image[12]=0xfe;
f=fopen("build/cpu-wide-v2-edge.b32","wb");if(!f)return 1;
if(fwrite(v2_image,1,32,f)!=32 || fclose(f))return 1;
bootImage("build/cpu-wide-v2-edge.b32");
verify(cpu.pc==0xfffffffeu && memoryRead(0xffffffffu)==0x12345678,"B32K v2 accepts the final two addressable words");
cpuCycle();verify(cpu.pc==0xffffffffu,"B32K v2 executes across the top of the address space");
snprintf(command,sizeof(command),"\"%s\" --emulator --boot build/cpu-wide-v2-edge.b32 --max-cycles 1 > build/cpu-v2-limit.out 2>&1",argv[0]);
#ifdef _WIN32
verify(system(command)==2,"command-line B32K v2 boot honors cycle limit");
#else
verify(system(command)==512,"command-line B32K v2 boot honors cycle limit");
#endif
snprintf(command,sizeof(command),"\"%s\" --emulator --boot build/cpu-wide.b32 --max-cycles 1 > build/cpu-limit.out 2>&1",argv[0]);
#ifdef _WIN32
verify(system(command)==2,"command-line cycle limit exit status");
#else
verify(system(command)==512,"command-line cycle limit exit status");
#endif
f=fopen("build/cpu-page-fail.b32","wb");if(!f)return 1;
fwrite("B32K",1,4,f);put16(f,2);put16(f,24);put32(f,0x20000);put32(f,0x20000);
put32(f,1);put32(f,0xf000);put32(f,0xf000);if(fclose(f))return 1;
reset_cpu(1);const char *page_fail_path="build/cpu-page-fail.b32";
for(unsigned i=0;page_fail_path[i];i++)memoryWrite(0x100+i,page_fail_path[i]);
failNextSparsePageAllocation=1;
verify(runWideImageFromGuest(0x100)==-5 && memoryPage(0x20,0)==NULL && memoryRead(0x20000)==0,
"B32 app image allocation failure leaves its sparse region untouched");
reset_cpu(1);ram.memory[0x300]=0xf000;ram.memory[0x301]=7;
ram.memory[0xf000]=0x4233324b;ram.memory[0xf001]=0x00180002;ram.memory[0xf002]=0x20000;ram.memory[0xf003]=0x20000;
ram.memory[0xf004]=1;ram.memory[0xf005]=0xe000;ram.memory[0xf006]=0xe000;
verify(runWidePackedFromGuest(0x300)==0,"native app loads and executes from packed guest RAM image");
reset_cpu(1);ram.memory[0x300]=0xf000;ram.memory[0x301]=7;
ram.memory[0xf000]=0x4233324b;ram.memory[0xf001]=0x00180002;ram.memory[0xf002]=0x20000;ram.memory[0xf003]=0x20000;
ram.memory[0xf004]=1;ram.memory[0xf005]=0xe000;ram.memory[0xf006]=0;
verify(runWidePackedFromGuest(0x300)==-4,"native app checksum corruption rejected before execution");
reset_cpu(1);ram.memory[0x300]=0xf000;ram.memory[0x301]=7;
ram.memory[0xf000]=0x4233324b;ram.memory[0xf001]=0x00180002;ram.memory[0xf002]=0x20000;ram.memory[0xf003]=0x20000;
ram.memory[0xf004]=1;ram.memory[0xf005]=0xe000;ram.memory[0xf006]=0xe000;failNextSparsePageAllocation=1;
verify(runWidePackedFromGuest(0x300)==-5 && memoryPage(0x10,0)==NULL,"native app reports insufficient sparse memory without partial load");
f=fopen("build/cpu-import.b32","wb");if(!f)return 1;
fwrite("B32K",1,4,f);put16(f,2);put16(f,24);put32(f,0x20000);put32(f,0x20000);put32(f,1);put32(f,0xe000);put32(f,0xe000);if(fclose(f))return 1;
reset_cpu(1);const char *import_path="build/cpu-import.b32";
for(unsigned i=0;import_path[i];i++)ram.memory[0x100+i]=import_path[i];
ram.memory[0x300]=0x100;ram.memory[0x301]=0xf000;ram.memory[0x302]=7;ram.memory[0xf000]=99;
verify(importWideImageFromGuest(0x300)==-5 && ram.memory[0xf000]==99,"native image import reports insufficient filesystem capacity without overwriting it");
ram.memory[0x302]=8;
verify(importWideImageFromGuest(0x300)==7 && ram.memory[0xf006]==0xe000,"native image import validates and packs a B32K v2 image");
ram.memory[0x310]=0xf000;ram.memory[0x311]=7;
verify(runWidePackedFromGuest(0x310)==0,"imported native image executes from packed filesystem storage");
bootImage("build/kernel.b16");verify(!cpu32,"legacy image selects compatibility mode");
f=fopen("build/cpu-input.basm","w");if(!f)return 1;
fputs("lea r0 2\ntrap 2\ntrap 0\n.stringz bob!\n",f);fclose(f);
f=fopen("build/cpu-input.in","wb");if(!f)return 1;
for(int i=0;i<255;i++)fputc('x',f);
fputs("\r\n",f);
for(int i=0;i<300;i++)fputc('x',f);
fputs("\nbuild/cpu-input.basm\n",f);fclose(f);
snprintf(command,sizeof(command),"\"%s\" --emulator < build/cpu-input.in > build/cpu-input.out 2>&1",argv[0]);
verify(system(command)==0,"assembly prompt recovers after oversized file name");
f=fopen("build/cpu-input.out","rb");if(!f)return 1;
char prompt_output[4096];size_t prompt_length=fread(prompt_output,1,sizeof(prompt_output)-1,f);fclose(f);prompt_output[prompt_length]=0;
verify(strstr(prompt_output,"Source file name exceeds 255 characters!") && strstr(prompt_output,"Starting execution!") && strstr(prompt_output,"bob!"),"oversized file name is consumed before next input");
char *first_long=strstr(prompt_output,"Source file name exceeds 255 characters!");
verify(first_long && !strstr(first_long+1,"Source file name exceeds 255 characters!"),"exact-limit CRLF filename is not reported as oversized");
puts("bob!");printf("%d CPU checks passed.\n",checks);return 0;
}
+892 -4
View File
@@ -9,12 +9,19 @@
#else
#define BOB "bob.exe"
#endif
#ifdef BOB_VERIFY
#define BOB32 "build\\bob32-next.exe"
#else
#define BOB32 "bob32.exe"
#endif
#define COMPILER "build\\bobcc.exe"
#else
#define BOB "./bob"
#define BOB32 "./bob32"
#define COMPILER "./build/bobcc"
#endif
static int checks;
static void storage_path(const char *path);
static void fail(const char *message) { fprintf(stderr,"Check failed: %s\n",message);exit(1); }
static void check(int condition,const char *message) { checks++;if(!condition)fail(message); }
static void write_text(const char *path,const char *text) {
@@ -43,6 +50,139 @@ static void guest(const char *source) {
check(system(BOB " --boot build/check.b16 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"guest execution");
char *output=read_text("build/check.out");check(!strcmp(output,"bob!\n"),"guest success marker");free(output);
}
static void guest32(const char *source) {
write_text("build/wide-lib.c",source);
check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/wide-lib.c -o build/wide-lib.i > build/compiler.log 2>&1")==0,"bob32 library guest preprocessing");
check(system(COMPILER " build/wide-lib.i build/wide-lib.basm build/wide-lib.b32 --wide > build/compiler.log 2>&1")==0,"bob32 library guest compilation");
write_text("build/check.in","");
check(system(BOB32 " --boot build/wide-lib.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"bob32 library guest execution");
char *output=read_text("build/check.out");check(!strcmp(output,"bob!\n"),"bob32 library success marker");free(output);
}
static void native_string_library(void) {
guest32(
"#include \"bob.h\"\n"
"#include \"bob_string.h\"\n"
"int main(void){\n"
"char text[64]=\"Bob\";char output[16];char command[64]=\"notes \\\"my note\\\" escaped\\\\ token\";\n"
"char malformed[24]=\"broken \\\"quote\";char *found;char *cursor;char *token;int valid;int parsed;\n"
"if(bob_strlen(text)!=3||bob_strcpy(text,\"Bob\")!=text)return 1;\n"
"if(bob_strcat(text,\"!\")!=text||bob_strcmp(text,\"Bob!\"))return 2;\n"
"found=bob_strchr(text,'!');if(!found||found-text!=3)return 3;\n"
"if(!bob_isspace('\\t')||bob_isspace('x'))return 4;\n"
"parsed=bob_parse_int(\" \\t-2147483648 \",&valid);if(!valid||parsed!=(-2147483647-1))return 5;\n"
"if(bob_format_int(parsed,output,16)!=11||bob_strcmp(output,\"-2147483648\"))return 6;\n"
"if(bob_format_int(-42,output,3)!=-1)return 7;\n"
"if(bob_parse_int(\"0x2a\",&valid)!=42||!valid)return 8;\n"
"bob_parse_int(\"2147483648\",&valid);if(valid)return 9;\n"
"bob_parse_int(\"12x\",&valid);if(valid)return 10;\n"
"cursor=command;if(bob_token_next(&cursor,&token)!=1||bob_strcmp(token,\"notes\"))return 11;\n"
"if(bob_token_next(&cursor,&token)!=1||bob_strcmp(token,\"my note\"))return 12;\n"
"if(bob_token_next(&cursor,&token)!=1||bob_strcmp(token,\"escaped token\"))return 13;\n"
"if(bob_token_next(&cursor,&token)!=0)return 14;\n"
"cursor=malformed;if(bob_token_next(&cursor,&token)!=1)return 15;\n"
"if(bob_token_next(&cursor,&token)!=-1)return 16;\n"
"bob_puts(\"bob!\");return 0;}\n");
write_text("build/string-app.c",
"#include \"bob.h\"\n#include \"bob_string.h\"\n"
"int main(void){char text[16]=\"Bob\";bob_strcat(text,\"!\");"
"if(bob_strlen(text)==4&&!bob_strcmp(text,\"Bob!\")){bob_puts(\"bob!\");return 0;}return 1;}\n");
check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/string-app.c -o build/string-app.i > build/compiler.log 2>&1")==0,"bob32 string app preprocessing");
check(system(COMPILER " build/string-app.i build/string-app.basm build/string-app.b32 --wide-app > build/compiler.log 2>&1")==0,"bob32 string app compilation");
storage_path("build/string-library-snapshot.b32");
write_text("build/check.in","import32 build/string-app.b32 stringlib\nrun stringlib\nsave\nhalt\n");
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"bob32 stores and runs a native string-library app");
char *output=read_text("build/check.out");contains(output,"Imported native app as stringlib");contains(output,"bob> bob!\nExit 0");contains(output,"Files saved to bob-files.b32");free(output);
write_text("build/check.in","restore yes\nrun stringlib\nhalt\n");
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"bob32 string-library app survives snapshot restore");
output=read_text("build/check.out");contains(output,"Files restored;");contains(output,"bob> bob!\nExit 0");free(output);
write_text("build/argv-app.c",
"#include \"bob.h\"\n#include \"bob_string.h\"\n"
"int main(int argc,char **argv){if(argc!=5)return argc;"
"if(bob_strcmp(argv[1],\"Bob OS\")||bob_strcmp(argv[2],\"escaped token\")||bob_strcmp(argv[3],\"\"))return 2;"
"bob_puts(\"bob!\");return 0;}\n");
check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/argv-app.c -o build/argv-app.i > build/compiler.log 2>&1")==0,"bob32 argv app preprocessing");
check(system(COMPILER " build/argv-app.i build/argv-app.basm build/argv-app.b32 --wide-app > build/compiler.log 2>&1")==0,"bob32 argv app compilation");
write_text("build/check.in","import32 build/argv-app.b32 argvapp\nrun argvapp \"Bob OS\" escaped\\ token \"\"\nhalt\n");
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"bob32 passes quoted arguments to native apps");
output=read_text("build/check.out");contains(output,"bob> bob!\nExit 0");free(output);
storage_path("build/snapshot.b16");
}
static void wide_guest(void) {
write_text("build/wide-check.c",
"#include \"bob.h\"\n"
"#include <stdbool.h>\n"
"#include <stddef.h>\n"
"int combine_values(int a,int b){return a+b;}\n"
"int double_value(int value){return value*2;}\n"
"int (*combine)(int,int)=combine_values;\n"
"int apply_value(int (*operation)(int),int value){return operation(value);}\n"
"int main(void) { int x=0x12345678; if(x+1!=0x12345679)return 1; "
"bool enabled=true; if(!enabled || false)return 10; enabled=false; if(enabled)return 11; "
"int values[3];size_t words=sizeof values;ptrdiff_t distance=&values[2]-&values[0];int *empty=NULL; "
"if(words!=3 || distance!=2 || empty!=NULL || (sizeof(int)-2)!=(size_t)-1)return 12; "
"if(combine(4,5)!=9)return 13; "
"int (*scale)(int (*)(int),int)=apply_value; if(scale(double_value,7)!=14)return 14; "
"if(-x!=-305419896)return 2; if((0x70000000+0x70000000)!=0xe0000000)return 3; "
"if(0x70000000*2!=0xe0000000)return 4; "
"if(0x70000000/7!=0x10000000 || 0x70000000%7)return 5; "
"if(-123456789/12345!=-10000 || -123456789%12345!=-6789)return 6; "
"if(0xf0000000u/3u!=0x50000000u || 0xf0000000u%3u)return 7; "
"if(0x80000000u>>1!=0x40000000u || (-8>>2)!=-2)return 8; "
"if((0xf0000000u>0x10000000u)==0)return 9; "
"bob_puts(\"bob!\"); return 0; }\n");
check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/wide-check.c -o build/wide-check.i > build/compiler.log 2>&1")==0,"wide guest preprocessing");
check(system(COMPILER " build/wide-check.i build/wide-check.basm build/wide-check.b32 --wide > build/compiler.log 2>&1")==0,"wide guest compilation");
FILE *image=fopen("build/wide-check.b32","rb");if(!image)fail("cannot read wide image");
char magic[4];check(fread(magic,1,4,image)==4 && !memcmp(magic,"B32K",4),"wide compiler emits B32K");
check(fgetc(image)==2 && fgetc(image)==0,"wide compiler emits B32K v2");fclose(image);
write_text("build/check.in","");
check(system(BOB " --boot build/wide-check.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"wide guest execution");
char *output=read_text("build/check.out");check(!strcmp(output,"bob!\n"),"wide guest success marker");free(output);
write_text("build/wide-small.c","#include \"bob.h\"\nint main(void){bob_puts(\"bob!\");return 0;}\n");
check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/wide-small.c -o build/wide-small.i > build/compiler.log 2>&1")==0,"small wide guest preprocessing");
check(system(COMPILER " build/wide-small.i build/wide-small.basm build/wide-small.b32 --wide > build/compiler.log 2>&1")==0,"small wide guest compilation");
image=fopen("build/wide-small.b32","rb");if(!image)fail("cannot read small wide image");
check(fseek(image,0,SEEK_END)==0 && ftell(image)<=24+511*4,"reachable helpers keep small bob32 app within one OS file");fclose(image);
check(system(BOB " --boot build/wide-small.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"small wide guest execution");
output=read_text("build/check.out");check(!strcmp(output,"bob!\n"),"small wide guest success marker");free(output);
check(system(BOB32 " --asm32 build/wide-small.basm < build/check.in > build/check.out 2> build/check.err")==0,"wide BASM direct assembly and execution");
output=read_text("build/check.out");check(!strcmp(output,"bob!\n"),"wide BASM success marker");free(output);
write_text("build/wide-types.c",
"#include \"bob.h\"\n"
"int main(void){long a=7L;unsigned long b=0xffffffffUL;long long c=3LL;"
"if(sizeof(long)!=1 || sizeof(a)!=1 || sizeof(unsigned long*)!=1 || sizeof(char)!=1 || sizeof(int[3])!=3)return 1;"
"if(a+c!=10 || b>>1!=0x7fffffffUL)return 2;bob_puts(\"bob!\");return 0;}\n");
check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/wide-types.c -o build/wide-types.i > build/compiler.log 2>&1")==0,"wide type guest preprocessing");
check(system(COMPILER " build/wide-types.i build/wide-types.basm build/wide-types.b32 --wide > build/compiler.log 2>&1")==0,"wide long type compilation");
check(system(BOB " --boot build/wide-types.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"wide type guest execution");
output=read_text("build/check.out");check(!strcmp(output,"bob!\n"),"wide long and sizeof semantics");free(output);
write_text("build/wide-bad.c","int main(void){return 1lul;}\n");
check(system("gcc -E -P -nostdinc -undef build/wide-bad.c -o build/wide-bad.i > build/compiler.log 2>&1")==0,"invalid wide suffix preprocessing");
check(system(COMPILER " build/wide-bad.i build/wide-bad.basm build/wide-bad.b32 --wide > build/compiler.log 2>&1")!=0,"invalid mixed integer suffix rejected");
output=read_text("build/compiler.log");contains(output,"invalid integer suffix");free(output);
write_text("build/wide-app.c","#include \"bob.h\"\nint main(void){bob_puts(\"bob!\");return 0;}\n");
check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/wide-app.c -o build/wide-app.i > build/compiler.log 2>&1")==0,"wide OS app preprocessing");
check(system(COMPILER " build/wide-app.i build/wide-app.basm build/wide-app.b32 --wide-app > build/compiler.log 2>&1")==0,"wide OS app compilation");
image=fopen("build/wide-app.b32","rb");if(!image)fail("cannot read wide OS app image");
unsigned char app_header[24];check(fread(app_header,1,sizeof(app_header),image)==sizeof(app_header),"wide OS app header read");fclose(image);
check(!memcmp(app_header,"B32K",4) && app_header[8]==0 && app_header[9]==0 && app_header[10]==2 && app_header[11]==0,"wide OS app uses supervised high-memory origin");
image=fopen("build/wide-app.b32","rb");if(!image)fail("cannot reopen wide app image");
fseek(image,0,SEEK_END);long image_size=ftell(image);rewind(image);unsigned char *image_bytes=malloc((size_t)image_size);if(!image_bytes)fail("wide app allocation");
check(fread(image_bytes,1,(size_t)image_size,image)==(size_t)image_size,"read wide app for large fixture");fclose(image);
uint32_t image_words=(uint32_t)image_bytes[16]|((uint32_t)image_bytes[17]<<8)|((uint32_t)image_bytes[18]<<16)|((uint32_t)image_bytes[19]<<24);
image_words+=600;for(int i=0;i<4;i++)image_bytes[16+i]=(unsigned char)(image_words>>(8*i));
check(image_words>511,"native B32 fixture exceeds the former per-file limit");
image=fopen("build/wide-large.b32","wb");if(!image)fail("create large B32 image");
check(fwrite(image_bytes,1,(size_t)image_size,image)==(size_t)image_size,"write large image prefix");
unsigned char zeros[2400]={0};check(fwrite(zeros,1,sizeof(zeros),image)==sizeof(zeros),"append large image payload");fclose(image);free(image_bytes);
image=fopen("build/wide-large.b32","rb");if(!image)fail("open large B32 image for truncated fixture");
unsigned char short_header[24];check(fread(short_header,1,sizeof(short_header),image)==sizeof(short_header),"read truncated image header");fclose(image);
image=fopen("build/wide-truncated.b32","wb");if(!image)fail("create truncated B32 image");
check(fwrite(short_header,1,sizeof(short_header),image)==sizeof(short_header),"write truncated image header");fclose(image);
write_text("build/check.in","");
check(system(BOB32 " --asm32 build/wide-app.basm < build/check.in > build/check.out 2> build/check.err")==0,"wide .org BASM assembly and direct application execution");
output=read_text("build/check.out");check(!strcmp(output,"bob!\n"),"wide-origin BASM application output");free(output);
}
static void console_and_commands(void) {
char *output=shell("help\necho bob!\nclear\nmem\nalloc 4\npoke 0xc000 -32768\npeek 0xc000\npoke 0 1\nhalt\n");
contains(output,"bob!\nbob16 OS:");contains(output,"help | echo TEXT");contains(output,"bob> bob!\n");
@@ -77,12 +217,34 @@ static void allocator_and_files(void) {
output=shell(large);contains(output,"full 511 chars (text)");free(output);
}
static void resident_compiler(void) {
char oversized[2048];strcpy(oversized,"cc bob.c keep\nedit large.c\nint main(void){\n");
for(int i=0;i<28;i++)strcat(oversized,"println(\"bob!\");\n");
strcat(oversized,"return 0;}\n.\ncc large.c keep\nrun keep\ngo bob.c\nhalt\n");
char *bounded=shell(oversized);contains(bounded,"C compile error near character");
contains(bounded,"bob!\nExit 0");not_contains(bounded,"Program fault");free(bounded);
char *joined=shell("edit joined.c\nint main(void){println(\"bo\" /* join */ \"b\" \"\"\n\"!\");return 0;}\n.\ngo joined.c\nhalt\n");
not_contains(joined,"compile error");contains(joined,"bob!\nExit 0");free(joined);
char *broken=shell("edit broken.c\nint main(void){println(\"bob!\n\");return 0;}\n.\ngo broken.c\n"
"edit broken.c\n:r 1 int main(void){int x='\n:r 2 ';return 0;}\n.\ngo broken.c\ngo bob.c\nhalt\n");
int errors=0;const char *error=broken;while((error=strstr(error,"C compile error near character"))){errors++;error++;}
check(errors==2,"resident rejects literal line breaks");contains(broken,"bob!\nExit 0");free(broken);
char *escapes=shell("edit escapes.c\nint main(void){if('\\a'!=7 || '\\b'!=8 || '\\f'!=12)return 1;\n"
"if('\\r'!=13 || '\\v'!=11 || '\\?'!=63)return 2;println(\"bob!\");return 0;}\n.\ngo escapes.c\nhalt\n");
not_contains(escapes,"compile error");contains(escapes,"bob!\nExit 0");free(escapes);
char *octal=shell("write octal.c int main(void){if(010!=8 || 077!=63 || 0177777!=0xffff)return 1;println(\"bob!\");return 0;}\ngo octal.c\nhalt\n");
not_contains(octal,"compile error");contains(octal,"bob!\nExit 0");free(octal);
octal=shell("write bad.c int main(void){return 09;}\ngo bad.c\nwrite bad.c int main(void){return 0200000;}\ngo bad.c\ngo bob.c\nhalt\n");
contains(octal,"C compile error near character");contains(octal,"bob!\nExit 0");free(octal);
char *output=shell("cc bob.c bob\nrun bob\necho bob!\nhalt\n");
contains(output,"Compiled 42 words.");contains(output,"bob> bob!\nExit 0\nbob> bob!\n");free(output);
output=shell("edit calc.c\nint main(void) { int n = 0; while (n < 3) { n = n + 1; }\nif (n == 3) { println(\"bob!\"); } else { return 1; } return 0; }\n.\ncc calc.c calc\nrun calc\nhalt\n");
not_contains(output,"compile error");contains(output,"bob> bob!\nExit 0");free(output);
output=shell("write math.c int main(void) { int a = 6 * 7; if (a / 2 == 21) println(\"bob!\"); return a % 7; }\ncc math.c math\nrun math\nhalt\n");
not_contains(output,"compile error");contains(output,"bob> bob!\nExit 0");free(output);
output=shell("edit product.c\nint main(void){int high=32767;int low=-32767-1;int i=0;\n"
"while(i<64){if(high*high!=1)return 1;if(low*high!=low)return 2;i++;}\n"
"if(low*2!=0 || (-7)*9!=-63)return 3;println(\"bob!\");return 0;}\n.\ngo product.c\nhalt\n");
not_contains(output,"compile error");not_contains(output,"Program timed out");contains(output,"bob!\nExit 0");free(output);
output=shell("write bad.c int main(void) { int a = ; }\ncc bad.c bad\nrun bad\ncc bob.c bob\nrun bob\nhalt\n");
contains(output,"C compile error near character");contains(output,"Program not found.");contains(output,"bob> bob!\nExit 0");free(output);
/* Verify both APIs and signed numeric formatting in resident-generated code. */
@@ -125,7 +287,7 @@ static void program_loading_and_recovery(void) {
contains(output,"Command too long.");contains(output,"Program not found.");free(output);
output=shell("load raw 0x4001 0xae01 98 0xf100 0x4001 0xae01 111 0xf100 0x4001 0xae01 98 0xf100 0x4001 0xae01 33 0xf100 0xe000\nrun raw\nhalt\n");
contains(output,"Loaded.");contains(output,"bob> bob!Exit 33");free(output);
output=shell("load bad 0x1001\nrun bad\nload spin 0x4601 0xb600 0x9000\nrun spin\necho bob!\nhalt\n");
output=shell("load bad 0x1001\nrun bad\nload spin 0x4601 0xb600 0xa000\nrun spin\necho bob!\nhalt\n");
contains(output,"Program fault; shell restored.");contains(output,"Program timed out; shell restored.");contains(output,"bob> bob!\n");free(output);
/* Load a program that tries to store to kernel address zero. */
output=shell("load guard 0x4201 0xae01 0 0x9040 0xe000\nrun guard\ncc bob.c bob\nrun bob\nhalt\n");
@@ -135,6 +297,236 @@ static void program_loading_and_recovery(void) {
contains(output,"Program fault; shell restored.");contains(output,"bob> bob!\n");free(output);
}
static void host_compiler_and_runtime(void) {
guest("#include <stdbool.h>\n#include \"bob.h\"\nint main(void){bool enabled=true;if(!enabled||false)return 1;enabled=false;if(enabled)return 2;bob_puts(\"bob!\");return 0;}");
guest("#include <stddef.h>\n#include \"bob.h\"\nint main(void){int values[3];size_t words=sizeof values;ptrdiff_t distance=&values[2]-&values[0];int *empty=NULL;if(words!=3||distance!=2||empty!=NULL||(sizeof(int)-2)!=(size_t)-1)return 1;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint sum(int a,int b){return a+b;}int (*combine)(int,int)=sum;int twice(int n){return n*2;}int apply(int (*fn)(int),int n){return fn(n);}int main(void){int (*operation)(int,int)=&sum;int (*scale)(int)=twice;int (*oldstyle)()=twice;if(combine(4,5)!=9||operation(2,3)!=5||scale(6)!=12||(*scale)(8)!=16||apply(*scale,7)!=14||oldstyle(5)!=10)return 1;operation=combine;if(operation(7,8)!=15)return 2;bob_puts(\"bob!\");return 0;}");
char *joined_literal=malloc(40000);if(!joined_literal)fail("allocate joined literal fixture");
char *joined_cursor=joined_literal;joined_cursor+=sprintf(joined_cursor,"#include \"bob.h\"\nchar *text=");
for(int i=0;i<9000;i++){memcpy(joined_cursor,"\"b\"",3);joined_cursor+=3;}
strcpy(joined_cursor,";int main(void){if(text[8999]!='b' || text[9000]!=0)return 1;bob_puts(\"bob!\");return 0;}");
guest(joined_literal);free(joined_literal);
char *large_literal=malloc(10000);if(!large_literal)fail("allocate large literal fixture");
char *literal_cursor=large_literal;literal_cursor+=sprintf(literal_cursor,"#include \"bob.h\"\nchar *text=\"");
memset(literal_cursor,'b',9000);literal_cursor+=9000;
strcpy(literal_cursor,"\";int main(void){if(text[8999]!='b' || text[9000]!=0)return 1;bob_puts(\"bob!\");return 0;}");
guest(large_literal);free(large_literal);
guest("#include \"bob.h\"\nint x;_Bool a=&x,b=\"bob!\",c=(_Bool)&x,d=(int*)0; "
"_Bool values[2]={&x,(void*)0};int main(void){static _Bool s=&x; "
"if(!a || !b || !c || d || !values[0] || values[1] || !s)return 1;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint (*p)[3]=(int (*)[3])0xc000+2; "
"int (*q)[3]=2+(int (*)[3])0xc000;int (*r)[3]=(int (*)[3])0xc009-1; "
"int distance=(int (*)[3])0xc009-(int (*)[3])0xc000; "
"int main(void){int (*base)[3]=(int (*)[3])0xc000; "
"if(p!=base+2 || q!=p || r!=p || distance!=3)return 1;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint a=7,b=9;int *p=1?&a:&b;int *q=0?&a:&b; "
"int *nil=0?&a:0;char *text=sizeof(a)==1?\"bob!\":\"bad\"; "
"int main(void){static int *s=1?(0?&b:&a):0; "
"if(*p!=7 || *q!=9 || nil!=0 || *s!=7)return 1;bob_puts(text);return 0;}");
guest("#include \"bob.h\"\nchar (*word)[5]=&\"bob!\";char (*end)[5]=&\"bob!\"+1; "
"char *last=&\"bob!\"[3];int main(void){static char (*saved)[5]=&\"bob!\"; "
"if(sizeof(*word)!=5 || (*word)[4]!=0 || (*saved)[3]!='!' || *last!='!')return 1; "
"if((*(end-1))[0]!='b')return 2;bob_puts(*saved);return 0;}");
guest("#include \"bob.h\"\nint main(void){char (*p)[5]=&\"bob!\";int a[2]; "
"if(sizeof(&a)!=1 || sizeof(*p)!=5 || (*p)[3]!='!')return 1;bob_puts(*p);return 0;}");
guest("#include \"bob.h\"\nint main(void){int x=0;int a[3]; "
"if(sizeof(sizeof(x++))!=1 || sizeof(sizeof(a))!=1 || x!=0)return 1;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint main(void){int a[2][3]={{1,2,3},{4,5,6}};unsigned int i=1; "
"if(i[a][2]!=6 || sizeof(i[a])!=3 || sizeof(2[a[0]])!=1)return 1;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint count;int f(int *p,int x){count++;return x;} "
"int main(void){int x;void *p=&x;if(sizeof(f(p,count++))!=1 || count!=0)return 1; "
"if(sizeof(bob_run(count++))!=1 || count!=0)return 2;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint main(void){char word[]=\"bob!\";void *p=word;bob_puts(p);return 0;}");
guest("#include \"bob.h\"\nint value=7;void *shared=&value;int *items[]={&value,1-1}; "
"int main(void){void *v=&value;int *p=v;_Bool b=p;int *a[2]={p,0}; "
"static int *saved=&value;if(*p!=7 || !b || a[1]!=0 || *saved!=7)return 1; "
"if(shared!=p || items[0]!=p || items[1]!=0)return 2;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint read(int *p){return *p;}int null(int *p){return p==0;} "
"int generic(void *p){return read(p);}_Bool truth(_Bool b){return b;} "
"int main(void){int x=7;void *v=&x;if(read(v)!=7 || generic(&x)!=7 || !null(1-1))return 1; "
"if(!truth(&x) || truth((int*)0))return 2;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint value=7;void *generic(void){return &value;} "
"int *returned(void){return generic();}int *empty(void){return 1-1;} "
"_Bool truth(void){return &value;}_Bool zero(void){return (int*)0;} "
"int main(void){if(*returned()!=7 || empty()!=0 || truth()!=1 || zero()!=0)return 1;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint main(void){int x=7;int *p;void *v;_Bool flag; "
"p=&x;v=p;p=v;flag=p;if(*p!=7 || flag!=1)return 1; "
"p=1-1;flag=p;if(p!=0 || flag!=0 || sizeof(p=0)!=1)return 2; "
"bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint main(void){int x=7;int *p=&x,*empty=0;void *v=p; "
"if(p!=v || v!=p || p==0 || 0==p || empty!=1-1)return 1; "
"if(sizeof(p==v)!=1 || p!=p || empty!=(void*)0)return 2;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint main(void){int low=-32768,high=32767,one=1,minus=-1; "
"for(int i=0;i<64;i++){if(low/one!=low || high/one!=high || high/minus!=-32767)return 1;} "
"if(-43/7!=-6 || 43/-7!=-6 || -43/-7!=6 || 43/7!=6)return 2; "
"if(-43%7!=-1 || 43%-7!=1 || -43%-7!=-1 || low%one!=0)return 3; "
"bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint depth=5;int leaf(void){return 7;} "
"int recurse(void){if(depth==0)return leaf();depth--;return recurse()+1;} "
"int main(void){int saved=42;int result=recurse(); "
"if(result!=12 || saved!=42 || leaf()!=7)return 1;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint main(void){int n=0;int *p=&n; "
"if(!!n!=0 || !!p!=1 || !!(-32768)!=1 || !!0xffff!=1)return 1; "
"if(!!n++!=0 || n!=1 || !!n++!=1 || n!=2)return 2;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint main(void){int high=32767,low=-32768;unsigned all=65535U; "
"for(int i=0;i<64;i++){if(high*high!=1 || low*high!=-32768)return 1;} "
"if(low*2!=0 || low*(-1)!=low || all*all!=1U || (-7)*9!=-63)return 2; "
"if(high*0!=0 || 0*high!=0 || (-1)*(-1)!=1)return 3;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint main(void){int rows[2][2];int (*p)[]=&rows[0];int (*q)[2]=&rows[1]; "
"if(sizeof(*(1?p:q))!=2 || sizeof(*(0?q:p))!=2)return 1; "
"int x=7;int *v=1?&x:1-1;int *w=0?0:&x;void *generic=0?(void*)0:v; "
"if(*v!=7 || *w!=7 || generic!=v || (1?0:v)!=0)return 2;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nenum E{ZERO,ONE};int main(void){enum E rows[2][2]; "
"enum E (*first)[2]=&rows[0];int (*last)[2]=(int (*)[2])&rows[1]; "
"if(last-first!=1 || first-last!=-1 || sizeof(last-first)!=1)return 1; "
"enum E *a=&rows[0][0];int *b=(int*)&rows[0][1]; "
"if(b-a!=1 || a-b!=-1)return 2;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\ntypedef int Word;enum E{ITEM=3};int const global=7; "
"unsigned const int high=65535U;char const message[]=\"bob!\"; "
"int inspect(int const value){Word const local=value;enum E const e=ITEM; "
"const const int *const const p=&global;return local+e+*p;} "
"int main(void){if(inspect(2)!=12 || high/3U!=21845U || sizeof(int const)!=1)return 1; "
"if(sizeof(unsigned const int)!=1 || sizeof(Word const)!=1)return 2; "
"bob_puts(message);return 0;}");
guest("#include \"bob.h\"\nenum Choice{FIRST=1,SECOND=2};int main(void){unsigned value=65535U;int score=0; "
"switch(value){case 65535U:score++;break;default:return 1;} "
"enum Choice choice=SECOND;switch(choice){case FIRST:return 2;case SECOND:score++;break;} "
"_Bool flag=7;switch(flag){case 0:return 3;case 1:score++;break;} "
"if(score!=3)return 4;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\ntypedef const int ReadOnly;const int global=7; "
"int inspect(ReadOnly value){ReadOnly local=value;return local+global;} "
"int main(void){if(inspect(2)!=9)return 1;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint value=7;int * const pointer=&value; "
"int main(void){*pointer=8;if(value!=8)return 1;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\ntypedef const int *ReadPointer;int first=7,second=8; "
"int main(void){ReadPointer pointer=&first;pointer=&second;if(*pointer!=8)return 1; "
"bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint value=7;int main(void){int *writable=&value;const int *read_only=writable; "
"read_only=&value;if(*read_only!=7)return 1;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint main(void){const int values[2]={4,5};const int matrix[2][2]={{1,2},{3,4}}; "
"if(values[1]!=5 || matrix[1][0]!=3)return 1;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint inspect(int * const value);int inspect(int *value){return *value;} "
"int main(void){int value=7;if(inspect(&value)!=7)return 1;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint calls;void visit(void){calls++;} "
"int main(void){(void)42;visit();1?visit():visit();0?(void)7:visit(); "
"if((visit(),calls)!=4)return 1;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint main(void){int rows[2][2];int (*p)[]=&rows[0];int (*q)[2]=&rows[1]; "
"if(!(p<q) || !(q>p) || p>=q || q<=p || sizeof(p<q)!=1)return 1; "
"bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint pad0[4096],pad1[4096],pad2[4096],pad3[4096],pad4[4096],pad5[4096],pad6[4096];int data[4096]; "
"int main(void){int *low=&data[0],*high=&data[4095]; "
"if((int)low<0 || (int)high>=0)return 1; "
"if(!(low<high) || !(high>low) || !(low<=high) || !(high>=low))return 2; "
"if(high<low || low>high || !(low<=low) || !(high>=high))return 3; "
"bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nchar bytes[]=\"\\a\\f\\v\\?\\xff\\377\"; "
"int main(void){if(sizeof(bytes)!=7 || bytes[0]!=7 || bytes[1]!=12 || bytes[2]!=11 || bytes[3]!='?')return 1; "
"if(bytes[4]!=255 || bytes[5]!=255 || '\\xff'!=255 || '\\377'!=255)return 2; "
"bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\ntypedef int unsigned Word;typedef signed Integer; "
"signed int echo(int signed value);int signed echo(signed value){return value;} "
"int unsigned divide(unsigned int a,int unsigned b){return a/b;} "
"int main(void){Integer negative=-3;Word high=65535U;int signed a[2]={-1,-2}; "
"if(echo(negative)!=-3 || divide(high,3U)!=21845U || a[1]!=-2)return 1; "
"if(sizeof(signed)!=1 || sizeof(int unsigned)!=1 || ((int unsigned)-1>>15)!=1U)return 2; "
"bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nunsigned int constant=65535U/3U;unsigned folded=65535U>>15; "
"unsigned mixed=((-1)<1U);typedef unsigned Word; "
"Word divide(Word a,Word b){return a/b;} "
"int main(void){Word high=65535U,low=3U;int negative=-1; "
"if(high<low || !(high>low) || high<=low || !(high>=low) || !(low<high))return 1; "
"if(negative<1U || mixed!=0 || constant!=21845U || folded!=1U)return 2; "
"if(divide(high,low)!=21845U || high%low!=0U || divide(32768U,65535U)!=0U)return 3; "
"if(divide(65535U,32768U)!=1U || 65535U%32768U!=32767U)return 4; "
"Word shift=32769U;if((shift>>1)!=16384U)return 5;shift>>=15;if(shift!=1U)return 6; "
"high++;if(high!=0U)return 7;high--;if(high!=65535U || sizeof(Word)!=1)return 8; "
"if((Word)-1!=65535U || ((Word)negative/3U)!=21845U)return 9;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\ntypedef _Bool Flag;Flag truth=42,zero=0,table[2][2]={{-2,0},{7,0}}; "
"Flag argument(Flag a,Flag b){return a==1 && b==0;}Flag returned(void){return -9;} "
"int main(void){Flag local=-7;Flag a[3]={3,0,-1};static Flag stored=99; "
"if(truth!=1 || zero!=0 || table[1][0]!=1 || table[0][1]!=0 || local!=1 || stored!=1)return 1; "
"if(a[0]!=1 || a[1]!=0 || a[2]!=1 || argument(42,0)!=1 || returned()!=1)return 2; "
"if((_Bool)-8!=1 || (_Bool)0!=0 || (_Bool)&local!=1 || sizeof(Flag)!=1)return 3; "
"if((local=17)!=1 || (local*=3)!=1 || (local-=1)!=0)return 4; "
"if(local++!=0 || local!=1 || ++local!=1 || local--!=1 || local!=0)return 5; "
"if(--local!=1 || local!=1)return 6;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nenum Mode{FIRST=-2,SECOND,WIDTH=3,LAST=WIDTH+2}; "
"typedef enum Mode Mode;enum Mode selected=LAST;int values[WIDTH]={1,2,3}; "
"int identify(Mode m){return m;} "
"int main(void){Mode m=FIRST;if(m!=-2 || SECOND!=-1 || LAST!=5 || sizeof(Mode)!=1)return 1; "
"if(identify(selected)!=5 || sizeof(values)!=3)return 2; "
"{enum Mode{FIRST=7,WIDTH=2};enum Mode local=FIRST;int a[WIDTH];if(local!=7 || sizeof(a)!=2)return 3;} "
"if(FIRST!=-2 || WIDTH!=3)return 4; "
"for(enum {BOUND=2} i=0;i<BOUND;i++){enum {INNER=BOUND+1};int a[INNER];if(sizeof(a)!=3)return 5;} "
"switch(selected){case LAST:bob_puts(\"bob!\");break;default:return 6;}return 0;}");
guest("#include \"bob.h\"\ntypedef int Word,*Pointer,Row[3];typedef int Word; "
"typedef Row *Rows;typedef char Text[];typedef void Nothing;Word answer(Nothing);Word answer(Nothing){return 1;}Row matrix[2]={{1,2,3},{4,5,6}}; "
"Rows rows=matrix;Text message=\"bob!\"; "
"Word sum(Row p[]){return p[0][0]+p[1][2];} "
"int main(void){Word n=7;Pointer p=&n; "
"if(sizeof(Row)!=3 || sizeof(Rows)!=1 || sum(rows)!=7 || *p!=7)return 1; "
"{typedef char Word;Word local[2];if(sizeof(local)!=2)return 2;} "
"{int Word=9;if(Word!=9 || sizeof(Word)!=1)return 3;} "
"Word restored=8;for(Word i=0;i<1;i++){typedef Row Block;Block a={1,2,3};if(a[2]!=3)return 4;} "
"if(restored!=8 || ((Rows)matrix)[1][1]!=5 || answer()!=1)return 5;bob_puts(message);return 0;}");
guest("#include \"bob.h\"\nint original[3];extern int original[];int copy[sizeof(original)]; "
"int f(int p[][3]){int a[sizeof(*p)];return sizeof(a);} "
"int main(void){int a[4];int b[sizeof(a)+1]; "
"{char a[2];int inner[sizeof(a)];if(sizeof(inner)!=2)return 1;} "
"int c[sizeof(a)];if(sizeof(copy)!=3 || sizeof(b)!=5 || sizeof(c)!=4)return 2; "
"for(int a[2]={0,0};a[0]<1;a[0]++){int d[sizeof(a)];if(sizeof(d)!=2)return 3;} "
"switch(4){case sizeof(a):if(f((int (*)[3])original)!=3)return 4;bob_puts(\"bob!\");break;default:return 5;}return 0;}");
guest("#include \"bob.h\"\nint a[sizeof(\"bob!\")];int length=sizeof(a); "
"int constants[]={sizeof(\"bob!\"),sizeof(1+2),sizeof(int[2][3])}; "
"int main(void){int local[3];int side=0; "
"static int count=sizeof(local),quiet=sizeof(side++),zero[sizeof(\"bob!\")]; "
"if(length!=5 || constants[0]!=5 || constants[1]!=1 || constants[2]!=6)return 1; "
"if(count!=3 || quiet!=1 || side!=0 || sizeof(zero)!=5 || zero[4]!=0)return 2; "
"switch(5){case sizeof(\"bob!\"):bob_puts(\"bob!\");break;default:return 3;}return 0;}");
guest("#include \"bob.h\"\nstatic int count;extern int count;static int count; "
"static int values[2]={3,4},*pointer=values; "
"static int next(void);extern int next(void);int next(void){return ++count;} "
"static int read(void){extern int count;return count+pointer[1];} "
"int main(void){if(next()!=1 || next()!=2 || read()!=6)return 1; "
"bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint next(void){static int count=3;static int *p=&count;return (*p)++;} "
"int other(void){static int count;return ++count;} "
"int array(void){static int a[][2]={{1,2},{3,4}};static char word[]=\"bob!\"; "
"a[1][1]++;if(a[1][1]==6)bob_puts(word);return a[1][1];} "
"int main(void){if(next()!=3 || next()!=4 || other()!=1 || other()!=2)return 1; "
"if(array()!=5 || array()!=6)return 2; "
"{static int count=7;if(count++!=7)return 3;}{static int count=9;if(count!=9)return 4;}return 0;}");
guest("#include \"bob.h\"\nint value=7;int rows[2][3]={{1,2,3},{4,5,6}}; "
"int change(void){int value=99;{extern int value;extern int value;value=8; "
"extern int rows[][3];if(sizeof(rows)!=6 || rows[1][2]!=6)return 100;} "
"if(value!=99)return 101;return 0;} "
"int main(void){extern int value;extern int unused; "
"if(change()!=0 || value!=8)return 1; "
"{extern int rows[2][3];int (*p)[3]=rows;p[1][2]=9;} "
"if(rows[1][2]!=9)return 2;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nextern int value;int value;int value=7;extern int value; "
"extern int rows[][3];int rows[2][3]={{1,2,3},{4,5,6}};int rows[][3]; "
"int zeros[];int zeros[];extern int unused;extern int incomplete[]; "
"extern int *pointer;int *pointer=&value;extern int *pointer; "
"extern int helper(void);int helper(void){return *pointer;} "
"int main(void){if(value!=7 || helper()!=7 || sizeof(rows)!=6 || rows[1][2]!=6)return 1; "
"if(sizeof(zeros)!=1 || zeros[0]!=0)return 2;*pointer=8;if(value!=8)return 3; "
"bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint main(void){int a[2][3];int (*p)[3]=a;int i=0; "
"if(sizeof(p+=1)!=1 || sizeof(p-=1)!=1 || sizeof(a[i++][0]+=2)!=1 || sizeof(++i)!=1)return 1; "
"if(p!=a || i!=0)return 2;p+=1;if(p-a!=1)return 3; "
"p-=1;(*p)[0]=7;if(a[0][0]!=7)return 4;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint first(int (*)[]);int first(int (*)[3]); "
"int first(int (*p)[3]){return (*p)[2];} "
"int inspect(int (**)[3]);int inspect(int (**)[]); "
"int inspect(int (**p)[3]){return (**p)[1];} "
"int main(void){int rows[1][3]={{1,2,3}};int (*p)[3]=rows; "
"if(first(rows)!=3 || inspect(&p)!=2)return 1;bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint main(void){int a[3]={3,-16,0};int i=0,n=2,x=1,y=2; "
"if((a[i++]<<=n++)!=12 || i!=1 || n!=3 || a[0]!=12)return 1; "
"if((a[i++]>>=2)!=-4 || i!=2 || a[1]!=-4)return 2; "
"x<<=y<<=1;if(x!=16 || y!=4)return 3; "
"x>>=1+1;if(x!=4)return 4;x<<=0;if(x!=4)return 5; "
"bob_puts(\"bob!\");return 0;}");
guest("#include \"bob.h\"\nint matrix[2][3]={{1,2,3},{4,5,6}}; "
"int (*rows)[3]=matrix;int (*whole)[2][3]=&matrix;int (*incomplete)[]=(int (*)[])matrix; "
"int (*selected[2])[3]={&matrix[1],matrix}; "
@@ -316,6 +708,7 @@ static void compile_workflow(void) {
contains(output,"C source file not found.");
contains(output,"Usage: cc SOURCE [OUTPUT] | go SOURCE [OUTPUT]");
contains(output,"broken.c: line 2, column");
contains(output,"near token '@'.");
contains(output,"Use edit to fix the source.");
/* Four successful runs above; neither failed go may execute stale app. */
int exits=0;for(char *p=output;(p=strstr(p,"Exit 0"))!=NULL;p+=6)exits++;
@@ -341,6 +734,229 @@ static void storage_path(const char *path) {
check(setenv("BOB16_STORAGE",path,1)==0,"set snapshot fixture path");
#endif
}
static void wide_kernel_workflow(void) {
storage_path("build/wide-snapshot.b32");remove("build/wide-snapshot.b32");
write_text("build/check.in","mem\nalloc 4\npoke 0xd000 77\npeek 0xd000\npoke 0xc000 88\npeek 0xc000\ngo bob.c\nedit compat.c\nint main(void) {\nint n=0x12345678;\nif(n+1!=0x12345679 || n*2!=0x2468ACF0 || n/3!=101806632 || n%3)return 1;\nprintln(\"bob!\");\nreturn 0;\n}\n.\ngo compat.c\ndelete compat.c\nedit tern.c\nint main(void) {\nint a=0;\nint b=1?2:3;\nint c=0?4:1?5:6;\nint d=1?7:a++;\nif(b==2&&c==5&&d==7&&a==0)println(\"bob!\");\nreturn 0;\n}\n.\ngo tern.c\ndelete tern.c\nedit loops.c\nint main(void) {\nint i=0;\nint calls=0;\ndo { i++; if(i==2)continue; calls++; if(i==4)break; } while(i<10);\ndo { calls++; } while(0);\nif(calls==4)println(\"bob!\");\nreturn 0;\n}\n.\ngo loops.c\ndelete loops.c\nedit assign.c\nint main(void) {\nint a=0; int b=1; int i=0;\nint x=(a=b=3);\na+=2; b<<=2; b>>=1;\nif(x==3&&a==5&&b==6&&((i=i+1)==1))println(\"bob!\");\nreturn 0;\n}\n.\ngo assign.c\ndelete assign.c\nedit funcs.c\nint main(void) {\nannounce();\nif(add(fact(5),2)==122)println(\"bob!\");\nreturn 0;\n}\nint announce(void) {\nprintln(\"bob!\");\nreturn 0;\n}\nint fact(int n) {\nif(n<2)return 1;\nreturn n*fact(n-1);\n}\nint add(int x,int y) {\nint value=x+y;\nreturn value;\n}\n.\ngo funcs.c\ndelete funcs.c\nedit scope.c\nint main(void) {\nint value=3;\n{int value=8;if(value!=8)return 1;}\n{int value=9;if(value!=9)return 2;}\nint count=99;\nfor(int count=0;count<2;count++){int inner=count;if(inner!=count)return 3;}\nif(value==3&&count==99)println(\"bob!\");\nreturn 0;\n}\n.\ngo scope.c\ndelete scope.c\nwrite hex.c int main(void){print_hex(4660);println(\"bob!\");return 0;}\ngo hex.c\nload old 0xD002 0xF200 0xF000 0x0062 0x006F 0x0062 0x0021 0x0000\nrun old\nedit note\nbob!\n.\nread note\nls\ncc bob.c app\nrun app\nsave\nhalt\n");
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"bob32 OS shell workflow");
char *output=read_text("build/check.out");int successful_apps=0;const char *success_cursor=output;
while((success_cursor=strstr(success_cursor,"bob!\nExit 0"))){successful_apps++;success_cursor+=11;}
check(successful_apps==9,"B32 resident programs all complete successfully");
contains(output,"bob32 OS:");contains(output,"Compiled 45 words.\nbob!\nExit 0");
contains(output,"bob!\nExit 0");
contains(output,"0x00001234bob!\nExit 0");
contains(output,"Loaded.\nbob> bob!\nExit 33");
contains(output,"0x0000D000: 0x0000004D (77)");contains(output,"poke is limited to heap RAM.");
contains(output,"bob!\n\n");contains(output,"Files saved to bob-files.b32");free(output);
FILE *snapshot=fopen("build/wide-snapshot.b32","rb");if(!snapshot)fail("bob32 snapshot missing");
char magic[4];check(fread(magic,1,4,snapshot)==4 && !memcmp(magic,"B32S",4),"bob32 OS writes native snapshot format");fclose(snapshot);
write_text("build/check.in","restore yes\nread note\nrun app\nhalt\n");
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"bob32 snapshot restore workflow");
output=read_text("build/check.out");contains(output,"Files restored;");contains(output,"bob!\n");contains(output,"bob> bob!\nExit 0");free(output);
write_text("build/check.in","go bob.c\nhalt\n");
check(system(BOB32 " --asm32 build/kernel32.basm < build/check.in > build/check.out 2> build/check.err")==0,"full bob32 kernel BASM assembly and execution");
output=read_text("build/check.out");contains(output,"bob32 OS:");contains(output,"Compiled 45 words.\nbob!\nExit 0");free(output);
write_text("build/check.in","run32 build/wide-app.b32\nrun32 build/missing-app.b32\ngo bob.c\nhalt\n");
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"bob32 OS runs a native wide C application");
output=read_text("build/check.out");contains(output,"bob> bob!\nExit 0");contains(output,"Cannot read B32 app image.");contains(output,"bob!\nExit 0");free(output);
write_text("build/check.in","import32 build/wide-large.b32 native\nls\nrun native\nrun32 native\nsave\nhalt\n");
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"import, run and snapshot a native app from bob32 RAM files");
output=read_text("build/check.out");contains(output,"Imported native app as native");contains(output,"native ");contains(output,"words (native bob32 image)");check(strstr(output,"bob> bob!\nExit 0") && strstr(strstr(output,"bob> bob!\nExit 0")+1,"bob!\nExit 0"),"run and run32 accept native guest filenames");contains(output,"Files saved to bob-files.b32");free(output);
write_text("build/check.in","restore yes\nrun native\nhalt\n");
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"restore and run native app stored in B32S");
output=read_text("build/check.out");contains(output,"Files restored;");contains(output,"bob> bob!\nExit 0");free(output);
write_text("build/check.in","import32 build/missing.b32 missing\nimport32 build/wide-bad.b32 corrupt\nimport32 build/wide-truncated.b32 short\nrun absent\nhalt\n");
write_text("build/wide-bad.b32","not a B32 image");
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"native image import errors preserve the shell");
output=read_text("build/check.out");contains(output,"Cannot read host app image path.");contains(output,"Invalid, truncated, corrupt, or unsupported B32K app image.");contains(output,"Program not found.");free(output);
storage_path("build/snapshot.b16");
}
static void wide_local_offset_limit(void) {
char source[4096] = "int main(void){";
char input[8192] = "edit offsets.c\n";
char piece[80];
for (int i = 0; i < 33; i++) {
snprintf(piece, sizeof(piece), "{int v%d=%d;}\n", i, i);
strcat(source, piece);
}
strcat(source, "return 0;}\n");
strcat(input, source);
strcat(input, ".\ncc offsets.c rejected\nhalt\n");
write_text("build/check.in", input);
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"B32 local offset limit shell workflow");
char *output = read_text("build/check.out");
contains(output, "C compile error");
check(strstr(output, "Compiled ") == NULL, "B32 local frame offset overflow rejected");
free(output);
}
static void wide_local_arrays(void) {
write_text("build/check.in",
"edit array.c\n"
"int main(void) {\n"
"int values[4]={1,2,},sum=0;\n"
"if(values[0]!=1||values[2]!=0)return 2;\n"
"for(int i=0;i<4;i++)values[i]=i+1;\n"
"values[0]++;\n"
"values[1]+=2;\n"
"values[2]<<=1;\n"
"for(int i=0;i<4;i++)sum+=values[i];\n"
"if(sum==16)println(\"bob!\");\n"
"return 0;\n"
"}\n"
".\ncc array.c array\nrun array\n"
"edit inc.c\n"
"int main(void) {\n"
"int a[2]={4,7},old=a[0]++;\n"
"if(old!=4||a[0]!=5)return 1;\n"
"if(++a[1]!=8)return 2;\n"
"int down=a[1]--;\n"
"if(down!=8||a[1]!=7)return 3;\n"
"if(--a[1]!=6)return 4;\n"
"println(\"bob!\");\n"
"return 0;\n"
"}\n"
".\ncc inc.c inc\nrun inc\n"
"edit excess.c\n"
"int main(void){int a[2]={1,2,3};return 0;}\n"
".\ncc excess.c rejected\nhalt\n");
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"B32 local array shell workflow");
char *output=read_text("build/check.out");
contains(output,"Compiled ");contains(output,"bob!\nExit 0");
char *first_success=strstr(output,"bob!\nExit 0");
check(first_success && strstr(first_success+1,"bob!\nExit 0"),"B32 array prefix and postfix increment expressions execute");
contains(output,"C compile error");free(output);
}
static void wide_array_parameters(void) {
write_text("build/check.in",
"edit arrays.c\n"
"int sum(int values[],int length);\n"
"int bump(int values[],int length);\n"
"int main(void){int values[3]={1,2,3};\n"
"int first=sum(values,3);\n"
"int next=bump(values,3);\n"
"if(first==6&&next==9&&sum(values,3)==9)println(\"bob!\");\n"
"return 0;}\n"
"int sum(int values[],int length){\n"
"int total=0;for(int i=0;i<length;i++)total+=values[i];\n"
"return total;}\n"
"int bump(int values[],int length){\n"
"for(int i=0;i<length;i++)values[i]++;\n"
"return sum(values,length);}\n"
".\ncc arrays.c arrays\nrun arrays\n"
"edit scalar_to_array.c\n"
"int read(int values[],int length);\n"
"int read(int values[],int length){return values[0];}\n"
"int main(void){int value=4;return read(value,1);}\n"
".\ncc scalar_to_array.c rejected1\n"
"edit array_to_scalar.c\n"
"int identity(int value);\n"
"int identity(int value){return value;}\n"
"int main(void){int values[2];return identity(values);}\n"
".\ncc array_to_scalar.c rejected2\n"
"edit conflicting_array.c\n"
"int f(int values[]);\n"
"int f(int values);\n"
"int main(void){return 0;}\n"
".\ncc conflicting_array.c rejected3\n"
"edit multidimensional.c\n"
"int bad(int values[][]);\n"
"int main(void){return 0;}\n"
".\ncc multidimensional.c rejected4\nhalt\n");
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"B32 array parameter shell workflow");
char *output=read_text("build/check.out");
contains(output,"bob> bob!\nExit 0");
char *error=strstr(output,"C compile error");
check(error && strstr(error+1,"C compile error") && strstr(strstr(error+1,"C compile error")+1,"C compile error") &&
strstr(strstr(strstr(error+1,"C compile error")+1,"C compile error")+1,"C compile error"),
"B32 rejects array argument and declaration mismatches");
free(output);
}
static void wide_resident_large_output(void) {
char input[8192] = "edit large.c\nint main(void){int a[1]={0};";
for (int i = 0; i < 60; i++) {
strcat(input, "a[0]++;");
if ((i == 6) || (i > 6 && (i - 6) % 9 == 8 && i < 59)) strcat(input, "\n");
}
strcat(input, "\n");
strcat(input, "if(a[0]==60)println(\"bob!\");return 0;}\n.\ncc large.c large\nrun large\nsave\nhalt\n");
storage_path("build/wide-resident-large.b32");remove("build/wide-resident-large.b32");
write_text("build/check.in", input);
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"B32 resident compiler creates and snapshots large app");
char *output=read_text("build/check.out");
char *compiled=strstr(output,"Compiled ");
check(compiled && atoi(compiled+9)>511,"B32 resident compiler output exceeds 511 words");
contains(output,"bob> bob!\nExit 0");contains(output,"Files saved to bob-files.b32");free(output);
write_text("build/check.in","restore yes\nrun large\nhalt\n");
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"B32 large resident app restores and runs from snapshot");
output=read_text("build/check.out");contains(output,"Files restored;");contains(output,"bob> bob!\nExit 0");free(output);
storage_path("build/snapshot.b16");
}
static void wide_function_prototypes(void) {
write_text("build/check.in",
"write bobs.c int main(void){println(\"Bob!\");return 0;}\n"
"go bobs.c\n"
"edit proto.c\n"
"int add(int a,int b);\n"
"int loose();\n"
"int unused(int);\n"
"int main(void){if(add(2,3)==5&&loose(4,5)==9)println(\"bob!\");return 0;}\n"
"int add(int a,int b){return a+b;}\n"
"int loose(int a,int b){return a+b;}\n"
".\ncc proto.c proto\nrun proto\n"
"edit mismatch.c\n"
"int f(int a);\n"
"int f(int a,int b);\n"
"int main(void){return 0;}\n"
".\ncc mismatch.c rejected\n"
"edit oldstyle_mismatch.c\n"
"int sum();\n"
"int main(void){return sum(1);}\n"
"int sum(int a,int b){return a+b;}\n"
".\ncc oldstyle_mismatch.c rejected\nhalt\n");
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"B32 function prototype shell workflow");
char *output=read_text("build/check.out");
contains(output,"Compiled ");contains(output,"Bob!\nExit 0");contains(output,"bob!\nExit 0");
char *errors=strstr(output,"C compile error");
check(errors && strstr(errors+1,"C compile error"),"B32 no-prototype declaration checks eventual definition arity");
free(output);
}
static void wide_function_pointers(void) {
write_text("build/check.in",
"edit pointer.c\n"
"int sum(int a,int b);\n"
"int main(void) {\n"
"int (*operation)(int,int)=sum;\n"
"int (*other)(int,int)=0;\n"
"other=operation;\n"
"operation=other;\n"
"if(operation(4,5)==9)println(\"bob!\");\n"
"return 0;\n"
"}\n"
"int sum(int a,int b){return a+b;}\n"
".\ncc pointer.c pointer\nrun pointer\n"
"edit mismatch.c\n"
"int one(int a);\n"
"int two(int a,int b);\n"
"int main(void){int (*operation)(int)=two;return 0;}\n"
".\ncc mismatch.c rejected\n"
"edit integer.c\n"
"int main(void){int value=7;int (*operation)(int)=value;return 0;}\n"
".\ncc integer.c rejected\n"
"edit mismatch_assign.c\n"
"int one(int a);int two(int a,int b);\n"
"int main(void){int (*operation)(int)=one;operation=two;return 0;}\n"
".\ncc mismatch_assign.c rejected\n"
"edit integer_assign.c\n"
"int main(void){int value=7;int (*operation)(int)=0;operation=value;return 0;}\n"
".\ncc integer_assign.c rejected\nhalt\n");
check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"B32 function pointer shell workflow");
char *output=read_text("build/check.out");
contains(output,"Compiled ");contains(output,"bob!\nExit 0");
char *errors=strstr(output,"C compile error");
int error_count=0;
while(errors){error_count++;errors=strstr(errors+1,"C compile error");}
check(error_count==4,"B32 function pointer rejects incompatible and non-function initializers and assignments");
free(output);
}
static void snapshot_mutate(int offset, int rehash) {
FILE *file=fopen("build/snapshot.b16","rb");if(!file)fail("snapshot missing");
unsigned char bytes[8640];size_t count=fread(bytes,1,sizeof(bytes),file);fclose(file);
@@ -405,7 +1021,271 @@ static void shell_editing(void) {
contains(output,"Allocation failed. Use a positive size");contains(output,"Used 1/8 slots");free(output);
}
static void host_language_rejections(void) {
write_text("build/check.i","int main(void){return 0;}");
write_text("build/check.basm","bob!\n");write_text("build/check.b16","bob!\n");write_text("build/check.map","bob!\n");
const char *collisions[]={
COMPILER " build/check.i build/check.b16 build/check.b16",
COMPILER " build/check.i build/check.map build/check.b16",
COMPILER " build/check.i build/check.basm build/check.map",
COMPILER " build/check.i build/check.i build/check.b16",
COMPILER " build/check.i build/check.basm build/check.i"
#ifdef _WIN32
,COMPILER " build/check.i build/./check.b16 build/check.b16"
,COMPILER " build/check.i build/CHECK.B16 build/check.b16"
#endif
};
for(unsigned i=0;i<sizeof(collisions)/sizeof(collisions[0]);i++) {
check(system(collisions[i])!=0,"colliding output paths rejected");
char *text=read_text("build/check.i");check(!strcmp(text,"int main(void){return 0;}"),"path rejection preserves source");free(text);
text=read_text("build/check.basm");check(!strcmp(text,"bob!\n"),"path rejection preserves assembly");free(text);
text=read_text("build/check.b16");check(!strcmp(text,"bob!\n"),"path rejection preserves binary");free(text);
text=read_text("build/check.map");check(!strcmp(text,"bob!\n"),"path rejection preserves map");free(text);
}
/* Feed malformed lexer input directly: a preprocessor would reject it first. */
const char *unterminated[]={"char *p=\"bob!\\", "int x='\\"};
for(unsigned i=0;i<sizeof(unterminated)/sizeof(unterminated[0]);i++) {
write_text("build/check.i",unterminated[i]);
write_text("build/check.basm","bob!\n");write_text("build/check.b16","bob!\n");
check(system(COMPILER " build/check.i build/check.basm build/check.b16 > build/compiler.log 2>&1")!=0,"unterminated escape rejected");
char *log=read_text("build/compiler.log");contains(log,"unterminated escape");free(log);
char *prior=read_text("build/check.basm");check(!strcmp(prior,"bob!\n"),"lexer failure preserves assembly");free(prior);
prior=read_text("build/check.b16");check(!strcmp(prior,"bob!\n"),"lexer failure preserves binary");free(prior);
}
const char *lexical[]={"char *p=\"bob!\n\";", "int x='\n';", "int x=08;", "int x=1u2;", "int x=1_foo;"};
const char *diagnostics[]={"newline in literal", "newline in literal", "malformed integer literal", "malformed integer literal", "malformed integer literal"};
for(unsigned i=0;i<sizeof(lexical)/sizeof(lexical[0]);i++) {
write_text("build/check.i",lexical[i]);
check(system(COMPILER " build/check.i build/check.basm build/check.b16 > build/compiler.log 2>&1")!=0,"malformed literal rejected");
char *log=read_text("build/compiler.log");contains(log,diagnostics[i]);free(log);
}
FILE *input=fopen("build/check.i","wb");if(!input)fail("cannot create zero-byte source");
fputs("int main(void){return 0;}",input);fputc(0,input);fputs("invalid trailing source",input);fclose(input);
check(system(COMPILER " build/check.i build/check.basm build/check.b16 > build/compiler.log 2>&1")!=0,"source zero byte rejects silent truncation");
char *log=read_text("build/compiler.log");contains(log,"zero byte in source");free(log);
char *prior=read_text("build/check.basm");check(!strcmp(prior,"bob!\n"),"input failures preserve assembly");free(prior);
prior=read_text("build/check.b16");check(!strcmp(prior,"bob!\n"),"input failures preserve binary");free(prior);
char *relocation_limit=malloc(20000);if(!relocation_limit)fail("allocate relocation limit fixture");
char *cursor=relocation_limit;cursor+=sprintf(cursor,"int x;");
for(int i=0;i<15;i++)cursor+=sprintf(cursor,"int a%d[4096];",i);
cursor+=sprintf(cursor,"int *p[4096]={");
for(int i=0;i<4096;i++){memcpy(cursor,"&x,",3);cursor+=3;}
strcpy(cursor,"};int main(void){return 0;}");
char *deep_expression=malloc(1024);if(!deep_expression)fail("allocate expression nesting fixture");
cursor=deep_expression;cursor+=sprintf(cursor,"int a[");
for(int i=0;i<400;i++)*cursor++='(';
*cursor++='1';
for(int i=0;i<400;i++)*cursor++=')';
strcpy(cursor,"];int main(void){return 0;}");
const char *sources[]={
relocation_limit,
deep_expression,
"int a[(int*)3];int main(void){return 0;}",
"int main(void){const int value=1;value=2;return 0;}",
"int main(void){const int value=1;value++;return 0;}",
"typedef const int ReadOnly;int main(void){ReadOnly value=1;value=2;return 0;}",
"int main(void){const int value=1;return sizeof(value=2);}",
"int update(const int value){value=2;return value;}int main(void){return 0;}",
"const int value=1;int main(void){value=2;return 0;}",
"int main(void){int value=1,other=2;int * const pointer=&value;pointer=&other;return 0;}",
"int main(void){int value=1;int * const pointer=&value;pointer++;return 0;}",
"int update(int * const pointer){int value=1;pointer=&value;return 0;}int main(void){return 0;}",
"typedef int * const Pointer;int main(void){int value=1,other=2;Pointer pointer=&value;pointer=&other;return 0;}",
"typedef int * Pointer;int main(void){int value=1,other=2;const Pointer pointer=&value;pointer=&other;return 0;}",
"int main(void){int value=1;const int *pointer=&value;*pointer=2;return 0;}",
"int main(void){int value=1;const int *pointer=&value;pointer[0]++;return 0;}",
"int main(void){int value=1;const int *pointer=&value;int *writable=pointer;return 0;}",
"int main(void){int value=1;const int **pointer=0;int **writable=pointer;return value;}",
"int inspect(int *value);int inspect(const int *value);int main(void){return 0;}",
"int *inspect(void);const int *inspect(void);int main(void){return 0;}",
"int main(void){const int values[2]={1,2};values[1]=3;return 0;}",
"int main(void){const int values[2]={1,2};values[1]++;return 0;}",
"int main(void){const int values[2]={1,2};int *writable=values;return 0;}",
"int main(void){const int values[2]={1,2};return sizeof(values[1]=3);}",
"const int value=1;int *writable=&value;int main(void){return 0;}",
"int main(void){const int value=1;int *writable=&value;return 0;}",
"int main(void){int * const pointer=0;int **writable=&pointer;return 0;}",
"int main(void){int value=1;const int *readonly=&value;int *writable=1?readonly:&value;return 0;}",
"enum E{value=(int*)3};int main(void){return 0;}",
"enum E{value=32768U};int main(void){return 0;}",
"int a[3]={[ (int*)1 ]=7};int main(void){return 0;}",
"int value(void);int a[value()];int main(void){return 0;}",
"int a[sizeof((int)(void)0)];int main(void){return 0;}",
"enum E{value=sizeof((int)(void)0)};int main(void){return 0;}",
"int main(void){int value=0;int a[2]={[value++]=1};return 0;}",
"int value(void);int main(void){switch(1){case value():return 0;}}",
"int main(void){int value=0;switch(1){case value++:return 0;}}",
"int main(void){void *p=(void*)0xc000;++*p;return 0;}",
"int main(void){void *p=(void*)0xc000;(*p)++;return 0;}",
"int main(void){int a[2];++a;return 0;}",
"int x=1,a;int *p=x?&a:0;int main(void){return 0;}",
"int a;char b;int *p=1?&a:&b;int main(void){return 0;}",
"int main(void){return sizeof(&1);}",
"int main(void){int x;return sizeof(&(x+1));}",
"int main(void){int x;return sizeof(&x++);}",
"int main(void){int x;return sizeof(&(int)x);}",
"int main(void){return sizeof(sizeof((void)0));}",
"int f(int x){return x;}int main(void){return sizeof(sizeof(f()));}",
"int main(void){void *p=0;return sizeof(sizeof(&p[0]));}",
"int main(void){int *p;return sizeof(sizeof(p=7));}",
"void f(void){}int main(void){int a[2];return sizeof(a[f()]);}",
"void f(void){}int main(void){int a[2];return sizeof(f()[a]);}",
"int main(void){void *p=0;return sizeof(&p[0]);}",
"int main(void){int (*p)[]=0;return sizeof(&p[0]);}",
"int f(int *p){return 0;}int main(void){return sizeof(f(7));}",
"int f(int x){return x;}int main(void){return sizeof(f());}",
"int f(void){return 0;}int main(void){return sizeof(f(1));}",
"int f(int *p){return 0;}int main(void){char x;return sizeof(f(&x));}",
"#include \"bob.h\"\nint main(void){int x;return sizeof(bob_run(&x));}",
"int main(void){bob_puts(7);return 0;}",
"int main(void){int x;bob_puts(&x);return 0;}",
"int main(void){char a[2];bob_gets(a,a);return 0;}",
"int main(void){char a[2];bob_snapshot(a,0);return 0;}",
"int main(void){int x;bob_putc(&x);return 0;}",
"int main(void){int x;return bob_run(&x);}",
"int main(void){int x;return bob_call(&x);}",
"int main(void){int *p=7;return 0;}",
"int main(void){int x;char *p=&x;return 0;}",
"int main(void){int x;int n=&x;return 0;}",
"int main(void){int *p[2]={0,7};return 0;}",
"int *p=7;int main(void){return 0;}",
"int x;char *p=&x;int main(void){return 0;}",
"int *p[2]={0,7};int main(void){return 0;}",
"int main(void){static int *p=7;return 0;}",
"void f(void){}int main(void){int x=f();return 0;}",
"int f(int *p){return 0;}int main(void){return f(7);}",
"int f(char *p){return 0;}int main(void){int x;return f(&x);}",
"int f(int n){return n;}int main(void){int x;return f(&x);}",
"int *f(void){return 7;}int main(void){return 0;}",
"int value;char *f(void){return &value;}int main(void){return 0;}",
"int value;int f(void){return &value;}int main(void){return 0;}",
"int main(void){int *p;p=7;return 0;}",
"int main(void){int *p;char *q;p=q;return 0;}",
"int main(void){int *p;int x;x=p;return 0;}",
"int main(void){int *p;return sizeof(p=7);}",
"int main(void){int *p;return p==7;}",
"int main(void){int *p;int zero=0;return p!=zero;}",
"int main(void){int *p;char *q;return p==q;}",
"int main(void){int *p;return sizeof(p==7);}",
"int x=1?1:(void)0;int main(void){return 0;}",
"int x=1||(void)0;int main(void){return 0;}",
"int x=0&&(void)0;int main(void){return 0;}",
"int x=(int)(void)0;int main(void){return 0;}",
"int main(void){int *p;char *q;1?p:q;return 0;}",
"int main(void){int *p;1?p:7;return 0;}",
"int main(void){int *p;int zero=0;1?p:zero;return 0;}",
"int main(void){int *p;char *q;return sizeof(1?p:q);}",
"enum A{X};enum B{Y};int main(void){enum A *a;enum B *b;return a-b;}",
"int main(void){int (*a)[2];int (*b)[3];return a-b;}",
"int main(void){int (*a)[2];int (*b)[];return a-b;}",
"int main(void){int *p;switch(p){}return 0;}",
"int main(void){int a[2];switch(a){}return 0;}",
"void f(void){}int main(void){switch(f()){}return 0;}",
"int main(void){switch(1){case (int*)0:break;}return 0;}",
"int main(void){switch(1){case (void)0:break;}return 0;}",
"void f(void){return 1;}int main(void){return 0;}",
"void f(void){}void g(void){return f();}int main(void){return 0;}",
"int f(void){return;}int main(void){return 0;}",
"void f(void){}int main(void){return f();}",
"void f(void){}int g(int x){return x;}int main(void){return g(f());}",
"void f(void){}void bob_putc(int);int main(void){bob_putc(f());return 0;}",
"void f(void){}int main(void){return f()+1;}",
"void f(void){}int main(void){return (int)f();}",
"void f(void){}int main(void){return sizeof((int)f());}",
"void f(void){}int main(void){return !f();}",
"void f(void){}int main(void){return f()&&1;}",
"void f(void){}int main(void){return 1||f();}",
"void f(void){}int main(void){int x;x=f();return 0;}",
"void f(void){}int main(void){int x;return sizeof(x=f());}",
"void f(void){}int main(void){return sizeof(f()+1);}",
"void f(void){}int main(void){1?f():1;return 0;}",
"void f(void){}int main(void){f()?1:2;return 0;}",
"void f(void){}int main(void){if(f())return 1;return 0;}",
"void f(void){}int main(void){while(f()){}return 0;}",
"void f(void){}int main(void){do{}while(f());return 0;}",
"void f(void){}int main(void){for(;f();){}return 0;}",
"int main(void){int *p;return p<1;}",
"int main(void){int *p;char *q;return p<q;}",
"int main(void){void *p,*q;return p<q;}",
"int main(void){int *p;return sizeof(p<1);}",
"char *p=\"\\x100\";int main(void){return 0;}",
"char *p=\"\\x100000000000000000000000000000\";int main(void){return 0;}",
"char *p=\"\\400\";int main(void){return 0;}",
"int int x;int main(void){return 0;}",
"unsigned unsigned x;int main(void){return 0;}",
"signed unsigned x;int main(void){return 0;}",
"unsigned signed x;int main(void){return 0;}",
"int signed int x;int main(void){return 0;}",
"int void x;int main(void){return 0;}",
"unsigned f(unsigned);unsigned f(int x){return x;}int main(void){return 0;}",
"unsigned x;int x;int main(void){return 0;}",
"int main(void){int *p;return (int)(p/2U);}",
"_Bool f(_Bool);_Bool f(int x){return x;}int main(void){return 0;}",
"_Bool x;int x;int main(void){return 0;}",
"enum E{A,A};int main(void){return 0;}",
"enum E{A};enum E{B};int main(void){return 0;}",
"enum E{};int main(void){return 0;}",
"enum E{A=32767,B};int main(void){return 0;}",
"enum E{A};int A;int main(void){return 0;}",
"int A;enum E{A};int main(void){return 0;}",
"int main(void){{enum E{A};}int a[A];return 0;}",
"int main(void){{enum E{A};}enum E e;return 0;}",
"enum E{A};int main(void){A=1;return 0;}",
"enum E{A};enum F{B};int f(enum E);int f(enum F x){return 0;}int main(void){return 0;}",
"typedef int T;typedef char T;int main(void){return 0;}",
"typedef int T;int T;int main(void){return 0;}",
"int T;typedef int T;int main(void){return 0;}",
"typedef int T;int T(void){return 0;}int main(void){return 0;}",
"int f(void);typedef int f;int main(void){return 0;}",
"int f(int x){typedef int x;return 0;}int main(void){return 0;}",
"int main(void){{typedef int Gone;}Gone x;return 0;}",
"typedef void Nothing;int main(void){Nothing x;return 0;}",
"int a[sizeof(later)];int later[3];int main(void){return 0;}",
"int main(void){{int hidden[3];}int a[sizeof(hidden)];return 0;}",
"int main(void){for(int hidden[2];0;){}int a[sizeof(hidden)];return 0;}",
"int main(void){int a[sizeof(a)];return 0;}",
"int x;static int x;int main(void){return 0;}",
"static int x;int x;int main(void){return 0;}",
"extern int x;static int x;int main(void){return 0;}",
"int f(void);static int f(void){return 0;}int main(void){return 0;}",
"extern int f(void);static int f(void);int main(void){return 0;}",
"static int a[];int main(void){return 0;}",
"int main(void){int x=1;static int y=x;return 0;}",
"int main(void){int x;static int *p=&x;return 0;}",
"int f(void){return 1;}int main(void){static int x=f();return 0;}",
"int main(void){static int x;static int x;return 0;}",
"int main(void){{static int hidden;}return hidden;}",
"int main(void){static int a[];return 0;}",
"int main(void){extern int missing;return missing;}",
"int x;int main(void){extern char x;return 0;}",
"int x;int main(void){int x;extern int x;return 0;}",
"int x;int main(void){extern int x;int x;return 0;}",
"int main(void){extern int x=1;return 0;}",
"int main(void){{extern int hidden;}return hidden;}",
"int main(void){extern int hidden;return 0;}int f(void){return hidden;}",
"extern int x;char x;int main(void){return 0;}",
"int x;int x=1;int x=2;int main(void){return 0;}",
"extern int x;int main(void){return x;}",
"extern int a[];int main(void){return sizeof(a);}",
"int a[2];extern int a[3];int main(void){return 0;}",
"int main(void){int *p,*q;p-=q;return 0;}",
"int main(void){int *p;int x=0;x+=p;return 0;}",
"int main(void){int *p,*q;return sizeof(p-=q);}",
"int main(void){int *p;return sizeof(p<<=1);}",
"int main(void){int a[2];return sizeof(a=0);}",
"int main(void){int a[2];return sizeof(a++);}",
"int main(void){return sizeof(1=2);}",
"int main(void){return sizeof(++1);}",
"int main(void){void *p;return sizeof(p+=1);}",
"int f(int (*)[]);int f(int (*)[2]);int f(int (*)[3]);int main(void){return 0;}",
"int f(int (*)[]);int f(char (*)[]);int main(void){return 0;}",
"int f(int (**)[]);int f(int (*)[]);int main(void){return 0;}",
"int main(void){int *p;p<<=1;return 0;}",
"int main(void){int *p;p>>=1;return 0;}",
"int main(void){int *p;return (int)(p<<1);}",
"int main(void){int *p;return sizeof(p>>1);}",
"int main(void){int *p;return (int)(p*2);}",
"int main(void){int *p;return sizeof(p|1);}",
"int main(void){int *p;return sizeof(~p);}",
"void a[2];int main(void){return 0;}",
"int a[2][];int main(void){return 0;}",
"int main(void){return sizeof(int[]);}",
@@ -443,6 +1323,7 @@ static void host_language_rejections(void) {
"int f(int x,int x){return x;}int main(void){return f(1,2);}",
"int main(void){switch(1){case 1:;case 1:return 0;}}",
"int main(void){switch(1){default:;default:return 0;}}",
"case 1:return 0;",
"int main(void){case 1:return 0;}",
"int main(void){switch(1){default:continue;}return 0;}",
"int a[1/0];int main(void){return 0;}",
@@ -475,16 +1356,23 @@ static void host_language_rejections(void) {
"int main(void){int a[4096][4096];return 0;}",
"int main(void){int a[2],b[2];return sizeof(a+b);}",
"int main(void){void *p;return sizeof(p+1);}",
"int main(void){int a[2];return sizeof(a[a]);}"
"int main(void){int a[2];return sizeof(a[a]);}",
"int one(int x){return x;}int two(int x,int y){return x+y;}int main(void){int (*p)(int)=two;return 0;}",
"int one(int x){return x;}int main(void){int (*p)(int)=one;return p(1,2);}",
"int main(void){int x=1;int (*p)(int)=&x;return 0;}",
"int main(void){int x;int (*p)(int)=(int (*)(int))&x;return 0;}"
};
for(unsigned i=0;i<sizeof(sources)/sizeof(sources[0]);i++) {
write_text("build/check.c",sources[i]);
write_text("build/check.basm","bob!\n");write_text("build/check.b16","bob!\n");
check(system("gcc -E -P -nostdinc -undef -I kernel build/check.c -o build/check.i > build/compiler.log 2>&1")==0,"language rejection preprocessing");
check(system(COMPILER " build/check.i build/check.basm build/check.b16 > build/compiler.log 2>&1")!=0,"invalid C must fail compilation");
if(i==0){char *diagnostic=read_text("build/compiler.log");contains(diagnostic,"code/relocation limit exceeded");free(diagnostic);}
if(i==1){char *diagnostic=read_text("build/compiler.log");contains(diagnostic,"expression nesting exceeds 256 levels");free(diagnostic);}
char *prior=read_text("build/check.basm");check(!strcmp(prior,"bob!\n"),"failed compile preserves BASM output");free(prior);
prior=read_text("build/check.b16");check(!strcmp(prior,"bob!\n"),"failed compile preserves binary output");free(prior);
}
free(deep_expression);free(relocation_limit);
}
static void image_validation(void) {
FILE *in=fopen("build/kernel.b16","rb");if(!in)fail("kernel image missing");
@@ -503,7 +1391,7 @@ static void basm_route(void) {
}
int main(void) {
console_and_commands();input_bounds();allocator_and_files();resident_compiler();
compiler_extensions();editor_and_aliases();
program_loading_and_recovery();host_compiler_and_runtime();host_language_rejections();file_management();compile_workflow();usability();persistence();shell_editing();image_validation();basm_route();
compiler_extensions();wide_guest();editor_and_aliases();
program_loading_and_recovery();native_string_library();host_compiler_and_runtime();host_language_rejections();file_management();compile_workflow();usability();persistence();shell_editing();image_validation();basm_route();wide_kernel_workflow();wide_local_arrays();wide_array_parameters();wide_resident_large_output();wide_function_prototypes();wide_function_pointers();wide_local_offset_limit();
printf("bob!\n%d checks passed.\n",checks);return 0;
}