Skip to content

Cob v0.0.9

Choose a tag to compare

@github-actions github-actions released this 09 Nov 23:51
· 9 commits to main since this release
c92cbc2

Cob Language v0.0.9

Overview

Three headline features, and one big reorganisation.

Functions. Cob has recipe and serve (a function and its return):

recipe fact(n):
    if n <= 1:
        serve 1
    serve n * fact(n - 1)

pop(fact(10))

A REPL. Run cob_interp with no file for an interactive session; a
bare expression prints its value, blocks continue with ..., and
variables and recipes persist. cob_interp file.cob -i runs a file and
then stays in the REPL with everything it defined. (Interpreter only.)

A real standard library. Everything that is not the core language is
now a separate shared library (.so / .dylib / .dll) loaded with
shuck, and every module and function in it is corn themed:
porch (console input), cornmath, kernels (text), almanac (time),
granary (files), pantry (SQLite), barn (windows), tassel
(Tcl/Tk) and silo (the everyday five in one shuck).

Added

  • recipe <name>(<params>): / serve [<expr>]: functions, with
    recursion (up to 500 calls deep, then a warning and a result of 0
    instead of a crash). Parameters and every name a recipe sets are
    local to it; any other name reads the global; a recipe cannot assign a
    global. Recipes are defined at the top level and are hoisted, so a
    call may appear above its recipe and recipes may call each other.
    A call can also stand alone on a line (greet("Ada")).
  • Call checking before anything runs: a call to a name that does not
    exist, or with the wrong number of arguments, is an error with its
    line number, so a typo fails up front, not halfway through the run.
    A forgotten shuck gets a hint naming the module to add.
  • The REPL in cob_interp (no file, --repl, or -i after a file):
    commands :help, :vars, :recipes, :load <file>, :reset,
    :quit; typing a recipe again replaces it; mistakes print an error
    and the session carries on. Prompts and the banner appear only on a
    terminal, so cob_interp --repl < script.txt is scriptable.
  • The standard library (stdlib/, built to bin/lib/ by
    make stdlib): porch, cornmath, kernels, almanac, granary,
    pantry, barn, tassel, silo. 40+ functions, listed in the README.
    shuck <module> finds the wrapper in the standard library directory
    ($COB_STDLIB, else <the tool's directory>/lib) after the current
    directory and cob_modules/; extern ... from "<module>" finds the
    library there too.
  • popcorn_comp gains recipes and the whole standard library,
    including SQLite and windows, which it could never compile before. It
    links -l<module> and records the standard library directory as an
    rpath.
  • make test and tools/tests/run_tests.sh: 17 checks, with every
    program test run through the interpreter AND the compiler against the
    same expected output.
  • A Docker image, built, smoke-tested and published to
    ghcr.io/cob-software-foundation/cob (linux/amd64 + linux/arm64) by
    the new .github/workflows/docker.yml: the interpreter and REPL, the
    compiler, farmer and the standard library (without barn and
    tassel). docker run -it --rm ghcr.io/cob-software-foundation/cob
    starts the REPL; see the README for running and compiling programs.
    The image build runs make test, and tools/docker/smoke_test.sh
    checks the finished image. The old stress-test image moved to
    Dockerfile.stress (ci.yml was updated to match).
  • make cob_interp_static: a build with the browser-capable modules
    compiled in, which is also what the WebAssembly build now uses.

Changed (BREAKING)

  • input, input_int, the SQLite keywords, the window keywords and
    tcl_eval / tk_eval are no longer built into the interpreter.

    They are standard library functions now and must be shucked:

    input(p)                      ->  shuck porch;   porch_ask(p)
    input_int(p)                  ->  shuck porch;   porch_ask_int(p)
    sql_open/exec/query/close     ->  shuck pantry;  pantry_open/exec/query/close
    window_open/label/wait/close/button/slider/textbox
                                  ->  shuck barn;    barn_open/label/wait/close/button/slider/textbox
    tcl_eval / tk_eval            ->  shuck tassel;  tassel_tcl / tassel_tk
    

    An old name gives an error that says exactly what to write instead.
    shuck cobwindow is gone with the keywords it acknowledged.

  • recipe and serve are new reserved words (so an extern cannot be
    named either); input, input_int and the others are no longer
    reserved.

  • One interpreter instead of three. cob_interp is the core language
    only and builds in about a second with no vendor libraries.
    cob_interp_full, cob_interp_db and cob_interp_window remain as
    make targets so old scripts keep working: each builds the same
    interpreter under the old name plus the modules that build used to
    contain.

  • Plain make no longer needs X11/OpenGL: it builds cob_interp,
    popcorn_comp, farmer and the standard library (which includes
    pantry). barn (raylib) and tassel (Tcl/Tk) are opt-in:
    make stdlib-barn, make stdlib-tassel.

  • A program or library file in the current directory shadows a standard
    library module of the same name (porch.cob is found before the real
    porch). Name your own files accordingly.

  • .strawberry cache format bumped from COBSTRW9 to COBSTRW10
    (the magic is one character longer). The built-in expression kinds
    were removed and the survivors renumbered; recipe, serve and
    call-statement kinds were added. Old caches are detected as stale and
    rebuilt automatically.

  • Library warnings are tagged by module ([porch] warning: ...,
    [pantry] warning: ...), and are now identical in the interpreter
    and in compiled programs, because both call the same library.

  • The harvest/trash --no-gc check now also looks inside pop(...)
    and conditions, in both tools.

  • In the WebAssembly build the sandbox notice is printed once per
    library, not once per function.

Fixed

  • popcorn_comp: set s = s + "x" lost the old value (the variable
    was freed before its own right-hand side was read), so a string built
    up in a loop ended up as just the last piece. The right-hand side is
    now evaluated first.
  • popcorn_comp: operand evaluation order. C leaves the order of
    function arguments unspecified, so a() + b() or a comparison of two
    calls that print could run b first in a compiled program. Compiled
    code now evaluates left to right, like the interpreter, whenever both
    operands do something observable.

Notes

  • barn and tassel are ports of the old built-in window and Tcl/Tk
    code. They compile against the vendored headers, but could not be
    built and run in the environment this release was developed in (no
    X11 extension headers for raylib; Tcl/Tk is a long from-source build),
    so they have not been run. Please try make stdlib-barn /
    make stdlib-tassel on a real desktop.
  • The release workflows (.github/workflows/build.yml) still package a
    single cob binary. Releases must also ship the lib/ directory
    next to it (cp -r bin/lib dist/), or shuck porch and friends will
    not find their libraries. make embed already includes it.
  • The standard library is loaded with dlopen()/LoadLibrary(), so
    cob_interp must be a dynamically linked executable, and a program
    compiled by popcorn_comp that uses it must be too: a statically
    linked program (such as a static-musl cross-compile target) cannot use
    shared libraries. Cross-compiling a program that shucks stdlib modules
    also needs those modules built for the target, with COB_STDLIB
    pointing at them. Check how the release binaries are linked before
    publishing 0.0.9. Programs that use only the core language are
    unaffected.
  • The Dockerfile and docker.yml could not be run in the environment this
    release was developed in (no Docker there). The build stage's commands
    were run by hand in a context filtered by .dockerignore, the runtime
    layout was reproduced and exercised, and the smoke test was dry-run
    (including a deliberately broken image, which it caught), but the first
    real image build will be the one on GitHub Actions. The arm64 half is
    built under QEMU and runs the full test suite there.
  • Tested here on Linux x86-64 with gcc, including under
    AddressSanitizer and UBSan. The macOS and Windows code paths (library
    naming, GetModuleFileName, .dll loading) are written but untested.

Cob Language v0.0.8

Overview

The headline feature is console input. Cob programs can now ask the
person running them a question and use the answer:

set name = input("What is your name? ")
set age = input_int("How old are you? ")
pop("Hello, " + name + "!")
pop(age + 1)

Added

  • input(<prompt>) prints the prompt (no trailing newline, flushed),
    reads one line from standard input, and returns it as a string with
    the line ending removed. At end of input it returns "". The prompt
    is optional: input() is allowed.
  • input_int(<prompt>) does the same and parses the line as a
    base-10 integer. A line that is not a number (or end of input) returns
    0; a non-numeric line also prints a warning on stderr.
  • input and input_int are now reserved words when followed by (,
    so an extern can no longer be declared with those names. A variable
    named input (no parentheses) still works.
  • popcorn_comp compiles input and input_int too, so compiled
    programs read standard input exactly like interpreted ones: same
    prompt handling, same end-of-input results, same non-numeric
    warning (tagged [cob] instead of [cob_interp], like every compiled
    warning). The input runtime is only added to the generated C for
    programs that use it, so every other program compiles to the same C
    as before.
  • A regression test, tools/tests/input.cob, with the lines it reads in
    input.stdin and its expected output in input.expected:
    cob_interp tools/tests/input.cob < tools/tests/input.stdin; sh tools/tests/input_native.sh
    checks the compiled binary against the interpreter.

Changed

  • In the WebAssembly build only (-DCOB_WASM), pop now flushes stdout
    after each line, so a host that captures output byte by byte sees it
    as it is printed instead of when libc's buffer fills.
  • .strawberry cache format bumped from COBSTRW8 to COBSTRW9.
    Two expression kinds (tags 19 and 20, input and input_int, one
    operand each) were appended after the existing ones, in both
    cob_interp and popcorn_comp. 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. The bump also means an older
    cob_interp that finds a cache written by this version re-parses the
    source instead of failing on a kind it does not know. popcorn_comp
    takes a .strawberry file as input, so regenerate it with
    cob_interp first if it complains about the magic.

Verified this session

  • Native binaries built by popcorn_comp and cob_interp give
    byte-identical stdout and identical warnings (modulo the [cob] tag)
    on tools/tests/input.cob with five different stdin files: normal,
    CRLF line endings with blank and non-numeric answers, immediate end
    of input, padded numbers with no trailing newline, and trailing junk
    or negatives; and on a program with a 100,000-character line, input
    inside while/if, and an expression as the prompt.
  • The generated C runs clean under AddressSanitizer + UndefinedBehavior-
    Sanitizer + LeakSanitizer on all of those inputs.

Fixed

  • popcorn_comp: testing a string for truthiness (if name:,
    while text:) leaked the string it tested. The compiled program's
    cob_truthy now frees it. Output was never affected; LeakSanitizer
    reported it on exit.

Not yet supported

  • The browser sandbox has no keyboard. Unless the host page supplies
    standard input (Pounce does), input() sees end of input.

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

Nothing everything not verified from v0.0.9-rc has been verified on a raspberry pi

the Rust rewrite

Cob is now written in Rust. The interpreter, compiler (popcorn_comp),
package manager (farmer), license tool (cob_sign), the browser build and
every standard-library module are Rust crates (crates/, stdlib-rs/);
barn wraps the vendored raylib/raygui C libraries and SQLite stays the
vendored amalgamation. The language, its error messages, the .strawberry
cache format, the native-extension ABI (include/cob.h) and the generated C
are unchanged -- checked by running the original and the new tools side by side.

  • tassel (Tcl/Tk) is removed, along with vendor/TCL, vendor/TK,
    make stdlib-tassel, and the tcl_eval/tk_eval upgrade hint.
  • Enterprise licenses can be bound to a machine. cob_sign sign now writes
    bind=machine by default: the first run records a hash of the OS machine UUID
    in the license file; --machine <hash> pre-binds a license in the signed
    part; --no-bind keeps the old behaviour. See ENTERPRISE.md for what this
    does and does not protect against.
  • The browser playground runs the Rust build (make play). Numbers there are
    64-bit like everywhere else (the old Emscripten build had 32-bit long).
  • Public keys now live in keys/drm_pubkeys.txt instead of a C header.
  • make wasm, make play, make wasm-test build and test the browser build;
    it needs the wasm32-unknown-unknown Rust target.
  • The miniz and monocypher vendor directories are gone (replaced by the
    zip crate and a Rust EdDSA that is byte-compatible with Monocypher's).
    Third-party crate licenses: legal/RUST_DEPENDENCIES.md.
  • Deep recursion/nesting no longer crashes the native interpreter.
  • cob_interp and popcorn_comp find their lib/ (and the bundled Zig) from argv[0]
    when /proc/self/exe is unavailable (chroots, minimal sandboxes); the C version failed
    there with "shuck ... failed" unless COB_STDLIB was set.
  • The stale tools/tests/input.cob test and input_native.sh are gone: they drove the
    input() builtin that 0.0.9 replaced with porch_ask(); porch_input and
    porch_cases.sh cover the same scenarios.