This is a cache of https://vccplus.brianholman.com/publications/vcc-plus-architecture/evidence/experiments/cmoc-regressions/run-py/. It is a snapshot of the page as it appeared on 2026-11-21T00:02:07.772+0000.
experiments/cmoc-regressions/run.py — supporting evidence · VCC Plus
← Supporting evidence

Evidence record

experiments/cmoc-regressions/run.py

From Windows Application to Portable Emulation Platform

7,753 bytes

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Run three compiler regressions across optimization, host, and guest axes."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import platform
import subprocess
import tempfile

FIXTURES = [
    ('indexed_subtraction', 'tests/toolchain/indexed-subtraction/qualification.c',
     'HX AC96806A0001A9F0008000EA42BE', []),
    ('indexed_arguments', 'tests/toolchain/indexed-arguments/qualification.c',
     'ARGS ' + '040C0810141C1820' * 3 + ' END', ['--no-relocate', '--switch=jump']),
    ('logical_negation', 'tests/toolchain/logical-negation.c',
     'NOT 010 1000 END', []),
]
def sha(data): return hashlib.sha256(data).hexdigest()
def main():
    parser = argparse.ArgumentParser(description=__doc__)
    for name in ('source', 'runtime', 'core', 'rom', 'output'):
        parser.add_argument('--' + name, type=Path, required=True)
    args = parser.parse_args()
    if args.output.exists(): parser.error('Choose a new result path; existing evidence is preserved.')
    source=args.source.resolve(strict=True);runtime=args.runtime.resolve(strict=True)
    core=args.core.resolve(strict=True);rom=args.rom.resolve(strict=True)
    inputs={}
    def retained(path):
        data=(source/path).read_bytes()
        inputs[path]=sha(data)
        return data
    fixture_data={name:retained(path) for name,path,_,_ in FIXTURES}
    harness=retained("tests/toolchain/run-compiled.cpp")
    for folder in (source/"src/core",source/"src/devices"):
        for path in sorted(folder.rglob("*")):
            if path.is_file(): retained(path.relative_to(source).as_posix())
    manifest=json.loads((runtime/'manifest.json').read_text())
    features={key:value for key,value in manifest.items() if key.startswith('vcc')}
    required=['vccIndexedByteSubtractionFix','vccIndexedArgumentLoadFix','vccAddZeroFlagsFix']
    if any(features.get(key)!=1 for key in required):raise ValueError('Runtime does not advertise all measured compiler corrections.')
    env=dict(os.environ,PATH=str(runtime/'bin')+os.pathsep+'/usr/bin:/bin')
    for key in ('CMOCPKGDATADIR','CMOCFLOATLIBDIR','VCC_CMOC_COMPAT','CPATH','C_INCLUDE_PATH','CPLUS_INCLUDE_PATH'):
        env.pop(key,None)
    env.setdefault('DEVELOPER_DIR','/Applications/Xcode.app/Contents/Developer')
    rows=[]
    with tempfile.TemporaryDirectory(prefix='vcc-paper-cmoc-') as directory:
        work=Path(directory);(work/'run-compiled.cpp').write_bytes(harness)
        # Reproduce the wrapper's data environment, but choose the real Mach-O
        # slice directly: an arch-selected shell need not propagate its slice.
        data_alias=work/'cmoc-data'
        data_alias.symlink_to(runtime/'share/cmoc',target_is_directory=True)
        env['CMOCPKGDATADIR']=str(data_alias)
        env['CMOCFLOATLIBDIR']=str(data_alias/'lib')
        runner=work/'run-compiled'
        build=['xcrun','clang++','-std=c++17','-O2','-mmacosx-version-min=14.0',
               '-I',str(source/'tests/toolchain'),str(work/'run-compiled.cpp'),str(core),'-o',str(runner)]
        subprocess.run(build,env=env,check=True,capture_output=True,text=True)
        runner_sha=sha(runner.read_bytes())
        for architecture in ('arm64','x86_64'):
            for optimization in ('-O0','-O2'):
                for name,path,expected,extra in FIXTURES:
                    (work/'fixture.c').write_bytes(fixture_data[name])
                    binary=work/'TEST.BIN'
                    command=['/usr/bin/arch','-'+architecture,str(runtime/'libexec/cmoc'),'--coco','--org=2800',
                             optimization,*extra,'-Werror','-o','TEST.BIN','fixture.c']
                    compiled=subprocess.run(command,cwd=work,env=env,capture_output=True,text=True,timeout=60)
                    if compiled.returncode:raise RuntimeError('Compiler failed for '+name+' '+architecture+' '+optimization)
                    executed=subprocess.run([str(runner),str(rom),str(binary),expected],
                        cwd=work,env=env,capture_output=True,text=True,timeout=60)
                    messages=[line.strip() for line in executed.stdout.splitlines() if line.startswith('PASS compiled CMOC program: ')]
                    passed=executed.returncode==0 and messages==['PASS compiled CMOC program: 6809','PASS compiled CMOC program: 6309']
                    rows.append({'fixture':name,'fixture_source':path,'requested_compiler_host_architecture':architecture,
                        'host_execution':'native' if architecture==platform.machine() else 'x86_64_under_Rosetta',
                        'optimization':optimization,'target_options':['--coco','--org=2800',optimization,*extra,'-Werror'],
                        'compiler_exit_code':compiled.returncode,'binary_sha256':sha(binary.read_bytes()),
                        'expected_screen_marker':expected,'runner_exit_code':executed.returncode,
                        'guest_results':[{'processor':p,'execution_mode':'emulation' if p=='HD6309' else 'not_applicable',
                                          'expected_marker_observed':passed} for p in ('MC6809','HD6309')],
                        'pass_messages':messages,'passed':passed})
                    print(name,architecture,optimization,'PASS' if passed else 'FAIL',flush=True)
                    if not passed:raise RuntimeError('Guest-output mismatch; no passing result claimed.')
        for path,digest in inputs.items():
            if sha((source/path).read_bytes())!=digest:raise RuntimeError('Source changed during experiment: '+path)
        record={'schema_version':1,'date':'2026-11-12','source_repository_url':'https://vccplus-git.brianholman.com/VCCPlus/VCCPlusOSS/src/branch/main/',
                'compiler_version':subprocess.check_output([str(runtime/'bin/cmoc'),'--version'],env=env,text=True).strip(),
                'compiler_executable_sha256':sha((runtime/'libexec/cmoc').read_bytes()),
                'compiler_wrapper_sha256':sha((runtime/'bin/cmoc').read_bytes()),
                'runtime_manifest_sha256':sha((runtime/'manifest.json').read_bytes()),'runtime_features':features,
                'core_library_sha256':sha(core.read_bytes()),'system_rom_sha256':sha(rom.read_bytes()),
                'system_rom_access':'read-only supplied input; bytes excluded from repository',
                'source_inputs_sha256':inputs,'harness_executable_sha256':runner_sha,
                'host':{'architecture':platform.machine(),'macos':platform.mac_ver()[0]},
                'guest_execution_host':'native arm64 harness for both guests; compiler slices selected independently',
                'compiler_slice_selection':'explicit arch invocation of libexec/cmoc with wrapper-equivalent data-alias environment',
                'runner_sha256':sha(Path(__file__).read_bytes()),'runs':rows,
                'compiled_artifacts':len(rows),'guest_executions':len(rows)*2,
                'all_passed':all(row['passed'] for row in rows),
                'limits':['Current corrected compiler only; historical before-fix failures cited separately',
                          'HD6309 reset emulation mode; no native-mode compiler-target claim',
                          'Compiler host slice and emulator host slice are independent; harness is arm64',
                          'Expected screen marker is the bounded observation; not complete language conformance',
                          'No physical Intel Mac or CoCo execution; no performance claim']}
        args.output.parent.mkdir(parents=True,exist_ok=True)
        args.output.write_text(json.dumps(record,indent=2)+'\n')
    print('Recorded',len(rows)*2,'passing guest executions.')
if __name__=='__main__':main()

SHA-2560cd334b03b981df9c9b2e9b25a97994d8ef6e1945958189bb246c45aef9440ce

A closer look

Open original