Repository navigation
Cob v0.0.8
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.inputandinput_intare now reserved words when followed by(,
so anexterncan no longer be declared with those names. A variable
namedinput(no parentheses) still works.popcorn_compcompilesinputandinput_inttoo, 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.stdinand its expected output ininput.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),popnow 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. .strawberrycache format bumped fromCOBSTRW8toCOBSTRW9.
Two expression kinds (tags 19 and 20,inputandinput_int, one
operand each) were appended after the existing ones, in both
cob_interpandpopcorn_comp. Existing caches are detected as
stale and rebuilt automatically the next time a script runs (you will
see onecache ... unreadable, reparsing sourcenote per script).
Nothing needs to be deleted by hand. The bump also means an older
cob_interpthat 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.strawberryfile as input, so regenerate it with
cob_interpfirst if it complains about the magic.
Verified this session
- Native binaries built by
popcorn_compandcob_interpgive
byte-identical stdout and identical warnings (modulo the[cob]tag)
ontools/tests/input.cobwith 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
insidewhile/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_truthynow 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_interpparses, caches and runs it.popcorn_compcompiles it to a plain Cif (...) { ... } else { ... }.
Added
-
if <condition>:runs its indented block when the condition is
true. The condition grammar is exactlywhile'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>:andelse:may follow anifat the
SAME indentation. Any number ofelifs, at most oneelse. -
Blocks nest freely:
ifinsideif, insidewhile, andwhile
insideif. -
if,elifandelseare now reserved words, so anexterncan no
longer be declared with one of those names (same rule aswhile,
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 indentationmalformed condition in if statement(orelif)expected ':' to open if block(orelif)
-
A signed Debian package and apt repository. One package,
csf-cob(apt package names must be lowercase, soapt install CSF-COBcannot work; it iscsf-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,farmerandpopcorn_comp
run that build, andpopcorn_compstill finds its bundled Zig. It
replaces the oldcobpackage 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-cobThe repository index (
InRelease,Release.gpg) is signed with the
project's GPG key, and the.debitself also has a detached signature
(csf-cob_<version>_all.deb.asc) plus a SHA-256 file, so it can be
checked by hand withgpg --verify. The repository lives on a
release namedapt-repoand 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
ifon the
website's release notes and download page.
Changed
.strawberrycache format bumped fromCOBSTRW7toCOBSTRW8.
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 onecache ... unreadable, reparsing sourcenote
per script). Nothing needs to be deleted by hand.elifis not a separate kind in the cache or the compiler: the
parser turns it into anifnested inside the previouselse, 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 intools/tests/if_statements.expected) covering if, if/else,
an if/elif/elif/else chain, anifnested inside anelifbranch
inside awhileloop, string equality and inequality, and the
truthiness of0and"", produces byte-identical output cold,
against its own.strawberrycache, and as a native binary built by
popcorn_comp. cob_interpcompiles clean under-Wall -Wextra -Wpedanticand 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/elsechain (a badelifcondition, a bad statement
inside anelsebody, a secondelse, a missing colon, anelse
with noif), 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 updateaccepts the signature,apt install csf-cobresolves its dependencies and installs,cobruns an
if/elsescript, 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 withUnable to locate package, as expected. - The
.debpackaging steps frombuild.ymlwere 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 theamd64build,
linkedcurrentto it, ran anif/elif/elsescript withcob,
compiled and ran it withpopcorn_compthrough 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
.debmakes 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
COBSTRW7cache and a truncatedCOBSTRW8cache 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 plainmake cob_interpbuild. - The
-DCOB_WASMconfiguration (the same definesmake wasmuses)
compiles natively and gives the same output on the test script.
Not verified
make wasmhas not been run here: Emscripten is not installed in
this environment. The code is plain C99 with no new dependencies and
the-DCOB_WASMflavor was compiled natively as described above, but
the first realemccbuild will be whatever CI run triggers it.
Pounce (the block-coding front end) builds from this source, so it
inherits that gap.- The
debandapt-repojobs have not run on GitHub Actions, signing
has not been run with the realGPG_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
.debis oneArchitecture: allpackage holding binaries for
several architectures, which is not how Debian packaging is normally
done and whichlintianwill complain about.dpkg --verifyreports
the deleted other-architecture files as missing, by design.apt
does not check detached.ascsignatures on a loose.deb; the
signature is for manual verification, not for anaptrepository. popcorn_comp's-Wpedanticbuild 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.