Skip to content

Cob v0.0.7

Choose a tag to compare

@github-actions github-actions released this 17 Oct 19:09
· 38 commits to main since this release

Cob Language v0.0.7

Overview

The headline feature is conditionals. Cob now has if, elif and
else:

set score = 85
if score >= 90:
    pop("grade: A")
elif score >= 80:
    pop("grade: B")
else:
    pop("keep practicing")

Both tools support it, and they print identical output for the same
program:

  • cob_interp parses, caches and runs it.
  • popcorn_comp compiles it to a plain C if (...) { ... } else { ... }.

Added

  • if <condition>: runs its indented block when the condition is
    true. The condition grammar is exactly while's: ==, !=, <,
    >, <=, >= on two numbers or two strings, or a bare expression
    as a truthiness test (non-zero for a number, non-empty for a string).
    Comparing a string to a number still warns and evaluates to false.

  • elif <condition>: and else: may follow an if at the
    SAME indentation. Any number of elifs, at most one else.

  • Blocks nest freely: if inside if, inside while, and while
    inside if.

  • if, elif and else are now reserved words, so an extern can no
    longer be declared with one of those names (same rule as while,
    set, pop, ...).

  • Clear syntax errors, each with a line number:

    • 'else' without a matching 'if' at the same indentation
    • 'elif' without a matching 'if' at the same indentation
    • malformed condition in if statement (or elif)
    • expected ':' to open if block (or elif)
  • A signed Debian package and apt repository. One package,
    csf-cob (apt package names must be lowercase, so apt install CSF-COB cannot work; it is csf-cob), carries all four Linux builds
    (amd64, i386, arm64, armhf). On install, the post-install script keeps
    the one that matches the machine (dpkg --print-architecture) and
    deletes the other three; /usr/bin/cob, farmer and popcorn_comp
    run that build, and popcorn_comp still finds its bundled Zig. It
    replaces the old cob package name. To install and keep it updated:

    sudo mkdir -p /etc/apt/keyrings
    curl -fsSL https://github.com/Cob-Software-Foundation/Cob/releases/download/apt-repo/cob-gpg-public-key.asc | sudo tee /etc/apt/keyrings/csf-cob.asc > /dev/null
    echo "deb [signed-by=/etc/apt/keyrings/csf-cob.asc] https://github.com/Cob-Software-Foundation/Cob/releases/download/apt-repo ./" | sudo tee /etc/apt/sources.list.d/csf-cob.list
    sudo apt update && sudo apt install csf-cob
    

    The repository index (InRelease, Release.gpg) is signed with the
    project's GPG key, and the .deb itself also has a detached signature
    (csf-cob_<version>_all.deb.asc) plus a SHA-256 file, so it can be
    checked by hand with gpg --verify. The repository lives on a
    release named apt-repo and keeps the newest three versions.
    The workflow refuses to publish if the signing key is not configured.

  • An "if / else" example on the in-browser playground, and if on the
    website's release notes and download page.

Changed

  • .strawberry cache format bumped from COBSTRW7 to COBSTRW8.
    A new statement kind (STMT_IF) was appended, with the condition
    followed by the then-block and the else-block. Existing caches are
    detected as stale and rebuilt automatically the next time a script
    runs (you will see one cache ... unreadable, reparsing source note
    per script). Nothing needs to be deleted by hand.
  • elif is not a separate kind in the cache or the compiler: the
    parser turns it into an if nested inside the previous else, so
    the cache reader/writer and the code generator only ever deal with
    if/else.

Verified this session

  • A test script (tools/tests/if_statements.cob, with its expected
    output in tools/tests/if_statements.expected) covering if, if/else,
    an if/elif/elif/else chain, an if nested inside an elif branch
    inside a while loop, string equality and inequality, and the
    truthiness of 0 and "", produces byte-identical output cold,
    against its own .strawberry cache, and as a native binary built by
    popcorn_comp.
  • cob_interp compiles clean under -Wall -Wextra -Wpedantic and runs
    clean under AddressSanitizer + UndefinedBehaviorSanitizer +
    LeakSanitizer on the valid program (cold and cached) and on seven
    malformed programs, including errors in the middle of an
    if/elif/else chain (a bad elif condition, a bad statement
    inside an else body, a second else, a missing colon, an else
    with no if), which free a half-built chain.
  • The package and the signed apt repository were exercised with the
    workflow's own scripts, serving the repository over HTTP to real apt
    with throwaway keys: apt update accepts the signature, apt install csf-cob resolves its dependencies and installs, cob runs an
    if/else script, an upgrade from one version to the next works and
    leaves only the matching build, a package list changed after signing
    is refused, an index signed by a different key is refused, and the
    oldest of four published versions is pruned. apt install CSF-COB
    fails with Unable to locate package, as expected.
  • The .deb packaging steps from build.yml were run end to end on an
    amd64 machine against a package tree laid out like the real Linux
    build artifacts. The package installed, kept only the amd64 build,
    linked current to it, ran an if/elif/else script with cob,
    compiled and ran it with popcorn_comp through the launcher (which
    found the Zig next to the real binary, not next to /usr/bin), and
    then removed cleanly.
  • Signing was exercised with throwaway keys, both unprotected and
    passphrase-protected: the signature verifies from an empty keyring
    holding only the published public key, a one-byte change to the
    .deb makes verification fail, no private key material appears in
    any published file, and the key and passphrase file are removed from
    the runner afterwards. A push with no key fails the job, a fork pull
    request builds unsigned and skips signing, and a protected key with no
    passphrase fails without producing a signature.
  • A COBSTRW7 cache and a truncated COBSTRW8 cache are both ignored
    with a note and the script is re-parsed correctly, rather than
    misread.
  • The existing arithmetic stress script still runs, and the widget
    smoke script still runs in a plain make cob_interp build.
  • The -DCOB_WASM configuration (the same defines make wasm uses)
    compiles natively and gives the same output on the test script.

Not verified

  • make wasm has not been run here: Emscripten is not installed in
    this environment. The code is plain C99 with no new dependencies and
    the -DCOB_WASM flavor was compiled natively as described above, but
    the first real emcc build will be whatever CI run triggers it.
    Pounce (the block-coding front end) builds from this source, so it
    inherits that gap.
  • The deb and apt-repo jobs have not run on GitHub Actions, signing
    has not been run with the real GPG_PRIVATE_KEY, and the repository has
    not yet been fetched through GitHub's release-asset URLs (which redirect
    to a CDN; apt follows redirects, but this was not tried against GitHub
    itself). In the local run the amd64 build
    was real but the Zig was a stand-in that forwards to gcc, and the
    i386, arm64 and armhf builds were placeholders, so those three were
    packaged but never installed or run on matching hardware.
  • The .deb is one Architecture: all package holding binaries for
    several architectures, which is not how Debian packaging is normally
    done and which lintian will complain about. dpkg --verify reports
    the deleted other-architecture files as missing, by design. apt
    does not check detached .asc signatures on a loose .deb; the
    signature is for manual verification, not for an apt repository.
  • popcorn_comp's -Wpedantic build still emits one warning about an
    over-long string literal in the C runtime preamble. It was already
    there before this release and this release did not touch it.
  • Everything Windows/macOS/cross-compile-related that previous
    releases flagged as not verified on real hardware remains not
    verified; this release touched none of that code.
  • The website changes (docs/index.html, docs/download.html,
    docs/play/index.html) were edited but not opened in a browser, and
    the new playground example has not been run in the WebAssembly
    playground.
  • The full CI suite (ci.yml, build.yml, the Docker stress image)
    has not been run on this change.