mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-08 20:28:30 +00:00
Add new calculator app
Cosmopolitan makes it easy to build and maintain programming languages, since it abstracts system call #ifdef toil, so you can focus on vision. Here's an example of a language that isn't turing complete, weighing in at <1,000 lines of modern C, intended to help with testing libc / libm: .1 .2 + .3 - abs epsilon < assert pi sqrt pi sqrt * pi - abs epsilon < assert -.5 rint dup 0 = assert signbit assert -.5 nearbyint dup 0 = assert signbit assert -.5 ceil dup 0 = assert signbit assert -.5 trunc dup 0 = assert signbit assert -.5 round -1 = assert -.5 floor -1 = assert 0 signbit ! assert CALCULATOR.COM pays homage to CALC.EXE recently removed from Windows 10. Microsoft should bundle this app instead. It too is roughly 100kb, works just fine w/ command prompt, and portable since it runs on Mac/Linux/BSD too while bundling even more features than the calculator on Google.com. It should be possible to run CALCULATOR.COM on Android and iOS too, just in case anyone needs a backend pipe driven framework, for graphical user interfaces of calculators. Sadly we haven't tried it since we don't know how to run software on telephones so the system call support is a priori
This commit is contained in:
parent
ac00be1a4e
commit
4918121810
6 changed files with 1062 additions and 51 deletions
116
tool/emacs/ctest-mode.el
Normal file
116
tool/emacs/ctest-mode.el
Normal file
|
@ -0,0 +1,116 @@
|
|||
(defconst ctest-operators
|
||||
'("+"
|
||||
"-"
|
||||
"*"
|
||||
"/"
|
||||
"%"
|
||||
"//"
|
||||
"**"
|
||||
"~"
|
||||
"^"
|
||||
"|"
|
||||
"&"
|
||||
">>"
|
||||
"<<"
|
||||
"!"
|
||||
"||"
|
||||
"&&"
|
||||
"="
|
||||
"!="
|
||||
"<"
|
||||
">"
|
||||
"<="
|
||||
">="))
|
||||
|
||||
(defconst ctest-consts
|
||||
'("false"
|
||||
"true"
|
||||
"e"
|
||||
"pi"
|
||||
"epsilon"
|
||||
"inf"
|
||||
"nan"
|
||||
"l2t"
|
||||
"lg2"
|
||||
"ln2"
|
||||
"l2e"))
|
||||
|
||||
(defconst ctest-builtins
|
||||
'("emit"
|
||||
"exit"
|
||||
"meminfo"
|
||||
"isnan"
|
||||
"isinf"
|
||||
"signbit"
|
||||
"isfinite"
|
||||
"isnormal"
|
||||
"fpclassify"))
|
||||
|
||||
(defconst ctest-functions
|
||||
'("emit"
|
||||
"cr"
|
||||
"key"
|
||||
"dup"
|
||||
"swap"
|
||||
"over"
|
||||
"drop"
|
||||
"expect"
|
||||
"assert"
|
||||
"abs"
|
||||
"min"
|
||||
"max"))
|
||||
|
||||
(defconst ctest-functions-libm
|
||||
'("mod"
|
||||
"rem"
|
||||
"gray"
|
||||
"ungray"
|
||||
"popcnt"
|
||||
"sqrt"
|
||||
"exp"
|
||||
"exp2"
|
||||
"exp10"
|
||||
"ldexp"
|
||||
"log"
|
||||
"log2"
|
||||
"log10"
|
||||
"sin"
|
||||
"cos"
|
||||
"tan"
|
||||
"asin"
|
||||
"acos"
|
||||
"atan"
|
||||
"atan2"
|
||||
"round"
|
||||
"trunc"
|
||||
"rint"
|
||||
"nearbyint"
|
||||
"ceil"
|
||||
"floor"
|
||||
"rand"
|
||||
"rand32"
|
||||
"rand64"))
|
||||
|
||||
(defun ctest--make-regex (words)
|
||||
(concat "\\_<" (regexp-opt words) "\\_>"))
|
||||
|
||||
(defconst ctest-highlights
|
||||
`(("\\(#.*\\)$" 1 font-lock-comment-face)
|
||||
("\\b0\\([xX]\\)[[:xdigit:]]+\\([ulUL]*\\)\\b"
|
||||
(1 font-lock-constant-face)
|
||||
(2 font-lock-constant-face))
|
||||
("\\b0\\([bB]\\)[01]+\\([ulUL]*\\)\\b"
|
||||
(1 font-lock-constant-face)
|
||||
(2 font-lock-constant-face))
|
||||
(,(concat "\\_<" (regexp-opt ctest-consts) "\\_>") .
|
||||
font-lock-constant-face)
|
||||
(,(concat "\\_<" (regexp-opt ctest-builtins) "\\_>") .
|
||||
font-lock-builtin-face)))
|
||||
|
||||
(define-derived-mode ctest-mode fundamental-mode "CALCULATOR.COM"
|
||||
"Major mode for editing CALCULATOR.COM smoke tests."
|
||||
(setq font-lock-defaults '(ctest-highlights)))
|
||||
|
||||
(add-to-list 'auto-mode-alist '("\\.ctest$" . ctest-mode))
|
||||
|
||||
(provide 'ctest-mode)
|
Loading…
Add table
Add a link
Reference in a new issue