Repository navigation
Cob v0.0.9
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 recipesets 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 forgottenshuckgets a hint naming the module to add. - The REPL in
cob_interp(no file,--repl, or-iafter 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, socob_interp --repl < script.txtis scriptable. - The standard library (
stdlib/, built tobin/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 andcob_modules/;extern ... from "<module>"finds the
library there too. popcorn_compgains 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 testandtools/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,farmerand the standard library (withoutbarnand
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 runsmake test, andtools/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_evalare no longer built into the interpreter.
They are standard library functions now and must beshucked: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_tkAn old name gives an error that says exactly what to write instead.
shuck cobwindowis gone with the keywords it acknowledged. -
recipeandserveare new reserved words (so anexterncannot be
named either);input,input_intand the others are no longer
reserved. -
One interpreter instead of three.
cob_interpis the core language
only and builds in about a second with no vendor libraries.
cob_interp_full,cob_interp_dbandcob_interp_windowremain as
maketargets so old scripts keep working: each builds the same
interpreter under the old name plus the modules that build used to
contain. -
Plain
makeno longer needs X11/OpenGL: it buildscob_interp,
popcorn_comp,farmerand the standard library (which includes
pantry).barn(raylib) andtassel(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.cobis found before the real
porch). Name your own files accordingly. -
.strawberrycache format bumped fromCOBSTRW9toCOBSTRW10
(the magic is one character longer). The built-in expression kinds
were removed and the survivors renumbered;recipe,serveand
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-gccheck now also looks insidepop(...)
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, soa() + b()or a comparison of two
calls that print could runbfirst in a compiled program. Compiled
code now evaluates left to right, like the interpreter, whenever both
operands do something observable.
Notes
barnandtasselare 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 trymake stdlib-barn/
make stdlib-tasselon a real desktop.- The release workflows (
.github/workflows/build.yml) still package a
singlecobbinary. Releases must also ship thelib/directory
next to it (cp -r bin/lib dist/), orshuck porchand friends will
not find their libraries.make embedalready includes it. - The standard library is loaded with dlopen()/LoadLibrary(), so
cob_interpmust be a dynamically linked executable, and a program
compiled bypopcorn_compthat 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, withCOB_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,.dllloading) 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.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
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 withvendor/TCL,vendor/TK,
make stdlib-tassel, and thetcl_eval/tk_evalupgrade hint.- Enterprise licenses can be bound to a machine.
cob_sign signnow writes
bind=machineby 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-bindkeeps 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-bitlong). - Public keys now live in
keys/drm_pubkeys.txtinstead of a C header. make wasm,make play,make wasm-testbuild and test the browser build;
it needs thewasm32-unknown-unknownRust target.- The
minizandmonocyphervendor directories are gone (replaced by the
zipcrate 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_interpandpopcorn_compfind theirlib/(and the bundled Zig) fromargv[0]
when/proc/self/exeis unavailable (chroots, minimal sandboxes); the C version failed
there with "shuck ... failed" unlessCOB_STDLIBwas set.- The stale
tools/tests/input.cobtest andinput_native.share gone: they drove the
input()builtin that 0.0.9 replaced withporch_ask();porch_inputand
porch_cases.shcover the same scenarios.