diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2018-12-14 20:21:03 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2018-12-14 20:21:03 -0800 |
| commit | 4fe63f253f58f87ab986fea38902d95f2a5ea338 (patch) | |
| tree | 12094f1c69b8ab375eb17507c959c43f9295c6c2 /lib | |
| parent | 6abec65843f0f37f7fc6032ac5db0fff3db71815 (diff) | |
Auto-updated to version 5
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/base64.nom | 76 | ||||
| -rw-r--r-- | lib/consolecolor.nom | 20 | ||||
| -rw-r--r-- | lib/file_hash.nom | 54 | ||||
| -rw-r--r-- | lib/object.nom | 118 | ||||
| -rw-r--r-- | lib/os.nom | 59 | ||||
| -rw-r--r-- | lib/things.nom | 195 |
6 files changed, 258 insertions, 264 deletions
diff --git a/lib/base64.nom b/lib/base64.nom index c48b42a..6f22afc 100644 --- a/lib/base64.nom +++ b/lib/base64.nom @@ -1,50 +1,50 @@ -#!/usr/bin/env nomsu -V4.12.12.8 +#!/usr/bin/env nomsu -V5.12.12.8 # This file defines actions for encoding/decoding base 64, as specified in: https://tools.ietf.org/html/rfc4648 -%b64_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" -%b64_chars = [: for % in 1 to (size of %b64_str): add (%b64_str::character %)] -%reverse_b64 = {: for %c in %b64_chars at %i: add %c = (%i - 1)} -%reverse_b64."=" = 64 -set %reverse_b64's metatable to {__index: -> 0} +$b64_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" +$b64_chars = [: for $ in 1 to (size of $b64_str): add ($b64_str|character $)] +$reverse_b64 = {: for $c in $b64_chars at $i: add $c = ($i - 1)} +$reverse_b64."=" = 64 +set $reverse_b64's metatable to {__index: -> 0} test: - %cases = ["", "Zg==", "Zm8=", "Zm9v", "Zm9vYg==", "Zm9vYmE=", "Zm9vYmFy"] - for %len = %encoded in %cases: - %plain = ("foobar"::from 1 to (%len - 1)) - assume (base64 %plain) == %encoded - assume (base64 decode %encoded) == %plain + $cases = ["", "Zg==", "Zm8=", "Zm9v", "Zm9vYg==", "Zm9vYmE=", "Zm9vYmFy"] + for $len = $encoded in $cases: + $plain = ("foobar"|from 1 to ($len - 1)) + assume (base64 $plain) == $encoded + assume (base64 decode $encoded) == $plain -externally [base64 %str, base64 encode %str, %str base64] all mean: - %chars = [] - for %i in 1 to (size of %str) via 3: - %bytes = [=lua "\%str:byte(\%i, \(%i + 2))"] - %chars::add %b64_chars.(((%bytes.1 & 252) >> 2) + 1) - if (size of %bytes) is: +externally [base64 $str, base64 encode $str, $str base64] all mean: + $chars = [] + for $i in 1 to (size of $str) via 3: + $bytes = [=lua "\$str:byte(\$i, \($i + 2))"] + $chars|add $b64_chars.((($bytes.1 & 252) >> 2) + 1) + if (size of $bytes) is: 3: - %chars::add %b64_chars.(((%bytes.1 & 3) << 4) + ((%bytes.2 & 240) >> 4) + 1) - %chars::add %b64_chars.(((%bytes.2 & 15) << 2) + ((%bytes.3 & 192) >> 6) + 1) - %chars::add %b64_chars.((%bytes.3 & 63) + 1) + $chars|add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1) + $chars|add $b64_chars.((($bytes.2 & 15) << 2) + (($bytes.3 & 192) >> 6) + 1) + $chars|add $b64_chars.(($bytes.3 & 63) + 1) 2: - %chars::add %b64_chars.(((%bytes.1 & 3) << 4) + ((%bytes.2 & 240) >> 4) + 1) - %chars::add %b64_chars.(((%bytes.2 & 15) << 2) + 1) - %chars::add "=" + $chars|add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1) + $chars|add $b64_chars.((($bytes.2 & 15) << 2) + 1) + $chars|add "=" 1: - %chars::add %b64_chars.(((%bytes.1 & 3) << 4) + 1) - %chars::add "=" - %chars::add "=" - return (%chars::joined) + $chars|add $b64_chars.((($bytes.1 & 3) << 4) + 1) + $chars|add "=" + $chars|add "=" + return ($chars|joined) -externally (chr %) means (=lua "string.char(\%)") -externally [decode base64 %str, %str base64 decoded, base64 decode %str] all mean: - %chars = [] - for %i in 1 to (size of %str) via 4: - %indices = [: for %j in %i to (%i + 3): add %reverse_b64.(%str::character %j)] - %chars::add (chr ((%indices.1 << 2) + ((%indices.2 & 48) >> 4))) - if ((%str::character (%i + 2)) == "="): stop - %chars::add (chr (((%indices.2 & 15) << 4) + ((%indices.3 & 60) >> 2))) - if ((%str::character (%i + 3)) == "="): stop - %chars::add (chr (((%indices.3 & 3) << 6) + %indices.4)) - return (%chars::joined) +externally (chr $) means (=lua "string.char(\$)") +externally [decode base64 $str, $str base64 decoded, base64 decode $str] all mean: + $chars = [] + for $i in 1 to (size of $str) via 4: + $indices = [: for $j in $i to ($i + 3): add $reverse_b64.($str|character $j)] + $chars|add (chr (($indices.1 << 2) + (($indices.2 & 48) >> 4))) + if (($str|character ($i + 2)) == "="): stop + $chars|add (chr ((($indices.2 & 15) << 4) + (($indices.3 & 60) >> 2))) + if (($str|character ($i + 3)) == "="): stop + $chars|add (chr ((($indices.3 & 3) << 6) + $indices.4)) + return ($chars|joined) diff --git a/lib/consolecolor.nom b/lib/consolecolor.nom index 31d4789..092105b 100644 --- a/lib/consolecolor.nom +++ b/lib/consolecolor.nom @@ -1,11 +1,11 @@ -#!/usr/bin/env nomsu -V4.12.12.8 +#!/usr/bin/env nomsu -V5.12.12.8 # This file defines actions for ANSI console color escape codes. test: - % = (bright "\(green)Color test passed.") + $ = (bright "\(green)Color test passed.") -%colors = {..} +$colors = {..} normal: 0, "reset color": 0, bright: 1, bold: 1, dim: 2, italic: 3, underscore: 4 "slow blink": 5, "fast blink": 6, reverse: 7, inverse: 7, inverted: 7 hidden: 8, # There's some other codes, but they're not currently implemented @@ -13,14 +13,14 @@ test: white: 37, "on black": 40, "on red": 41, "on green": 42, "on yellow": 43 "on blue": 44, "on magenta": 45, "on cyan": 46, "on white": 47 -for %name = %colornum in %colors: - %colornum = "\%colornum" +for $name = $colornum in $colors: + $colornum = "\$colornum" #(=lua "COMPILE_ACTIONS").%name = (..) [%nomsu, %tree] -> (Lua "'\\027[\(%colornum)m'") - %compile.action.%name = (..) - for (%compile %text): - if %text: - return (Lua "('\\027[\(%colornum)m'..\(%text as lua expr)..'\\027[0m')") + $compile.action.$name = (..) + for ($compile $text): + if $text: + return (Lua "('\\027[\($colornum)m'..\($text as lua expr)..'\\027[0m')") ..else: - return (Lua "'\\027[\(%colornum)m'") + return (Lua "'\\027[\($colornum)m'") diff --git a/lib/file_hash.nom b/lib/file_hash.nom index 32c7209..dd3d520 100644 --- a/lib/file_hash.nom +++ b/lib/file_hash.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.12.12.8 +#!/usr/bin/env nomsu -V5.12.12.8 # This file defines some actions for hashing files and looking up files by hash. @@ -7,47 +7,47 @@ use "lib/base64.nom" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -lua> "local \%use_sha1, \%hashlib = pcall(require, 'openssl.digest')" +lua> "local \$use_sha1, \$hashlib = pcall(require, 'openssl.digest')" test: assume (hash "hello world") == (hash "hello world") - assume ((hash "hello world") != (hash "goodbye")) or barf "\ - ..Hash collision: + assume ((hash "hello world") != (hash "goodbye")) or barf " + Hash collision: (hash "hello world") = \(hash "hello world") (hash "goodbye") = \(hash "goodbye")" assume (..) (..) - hash "\ - ..This is a really long string meant to stress test the hashing function and + hash " + This is a really long string meant to stress test the hashing function and ensure that it's not overflowing with long inputs." ..!= "inf" - assume ((hash "\000") != (hash "\000\000\000\000\000")) or barf "\ - ..Incorrect hashing of null strings" + assume ((hash "\000") != (hash "\000\000\000\000\000")) or barf \ + .."Incorrect hashing of null strings" - if %use_sha1: + if $use_sha1: assume ((hash "hello world") == "Kq5sNclPz7QV2+lfQIuc6R7oRu0=") -if %use_sha1: - externally (hash %) means: - %hash = (=lua "\%hashlib.new('sha1'):final(\%)") - return (base64 %hash) +if $use_sha1: + externally (hash $) means: + $hash = (=lua "\$hashlib.new('sha1'):final(\$)") + return (base64 $hash) ..else: # TODO: remove warning? say "\027[31;1mWARNING: OpenSSL module not found. Defaulting to a non-cryptographically secure hash function.\027[0m" - externally (hash %) means: - %bytes = (%::bytes) - %hash = (%bytes.1 << 7) - for %i in 2 to (size of %bytes): - %hash = ((1000003 * %hash) ~ %bytes.%i) - %hash = (%hash ~ (size of %bytes)) - return "\%hash" + externally (hash $) means: + $bytes = ($|bytes) + $hash = ($bytes.1 << 7) + for $i in 2 to (size of $bytes): + $hash = ((1000003 * $hash) ~ $bytes.$i) + $hash = ($hash ~ (size of $bytes)) + return "\$hash" -externally (file with hash %hash) means: - for %filename in (files for "."): - %contents = (read file %filename) - %file_hash = (hash %contents) - if (%file_hash == %hash): - return %filename +externally (file with hash $hash) means: + for $filename in (files for "."): + $contents = (read file $filename) + $file_hash = (hash $contents) + if ($file_hash == $hash): + return $filename -(hash of file %filename) parses as (hash (read file %filename)) +(hash of file $filename) parses as (hash (read file $filename)) diff --git a/lib/object.nom b/lib/object.nom index ca50257..a77af3f 100644 --- a/lib/object.nom +++ b/lib/object.nom @@ -1,8 +1,8 @@ -#!/usr/bin/env nomsu -V4.12.12.8 +#!/usr/bin/env nomsu -V5.12.12.8 # This file contains the implementation of an Object-Oriented programming system. -%globals.METAMETHOD_MAP = {..} +$globals.METAMETHOD_MAP = {..} "as text": "__tostring", "clean up": "__gc", "+ 1": "__add", "- 1": "__sub" "* 1": "__mul", "/ 1": "__div", "-": "__unm", "// 1": "__idiv", "mod 1": "__mod" "^ 1": "__pow", "& 1": "__band", "| 1": "__bor", "~ 1": "__bxor", "~": "__bnot" @@ -14,83 +14,83 @@ test: object (Dog): (Dog).genus = "Canus" my action [set up]: - %me.barks or= 0 + $me.barks or= 0 my action [bark, woof]: - %barks = [: for % in 1 to %me.barks: add "Bark!"] - return (%barks::joined with " ") + $barks = [: for $ in 1 to $me.barks: add "Bark!"] + return ($barks|joined with " ") - my action [get pissed off]: %me.barks += 1 - %d = (Dog {barks: 2}) - assume (type of %d) == "Dog" - assume (%d is a "Dog") - assume %d.barks == 2 - assume ((%d::bark) == "Bark! Bark!") - assume ((%d::woof) == "Bark! Bark!") - %d::get pissed off - assume (%d.barks == 3) - assume ((%d::bark) == "Bark! Bark! Bark!") - assume (%d.genus == "Canus") - assume ("\(%d.class)" == "Dog") - assume (%d.genus == "Canus") - assume (%d.barks == 3) - %d2 = (Dog {}) - assume (%d2.barks == 0) or barf "Default initializer failed" - with {%d: Dog {barks: 1}}: - assume ((%d::bark) == "Bark!") + my action [get pissed off]: $me.barks += 1 + $d = (Dog {barks: 2}) + assume (type of $d) == "Dog" + assume ($d is a "Dog") + assume $d.barks == 2 + assume (($d|bark) == "Bark! Bark!") + assume (($d|woof) == "Bark! Bark!") + $d|get pissed off + assume ($d.barks == 3) + assume (($d|bark) == "Bark! Bark! Bark!") + assume ($d.genus == "Canus") + assume ("\($d.class)" == "Dog") + assume ($d.genus == "Canus") + assume ($d.barks == 3) + $d2 = (Dog {}) + assume ($d2.barks == 0) or barf "Default initializer failed" + with {$d: Dog {barks: 1}}: + assume (($d|bark) == "Bark!") object (Corgi) extends (Dog): my action [sploot] "splooted" my action [bark, woof]: - %barks = [: for % in 1 to %me.barks: add "Yip!"] - return (%barks::joined with " ") + $barks = [: for $ in 1 to $me.barks: add "Yip!"] + return ($barks|joined with " ") - %corg = (Corgi {}) - assume (%corg.barks == 0) - with {%d: Corgi {barks: 1}}: - assume ((%d::sploot) == "splooted") or barf "subclass method failed" - assume ((%d::bark) == "Yip!") or barf "inheritance failed" - assume ((%d::woof) == "Yip!") + $corg = (Corgi {}) + assume ($corg.barks == 0) + with {$d: Corgi {barks: 1}}: + assume (($d|sploot) == "splooted") or barf "subclass method failed" + assume (($d|bark) == "Yip!") or barf "inheritance failed" + assume (($d|woof) == "Yip!") - with {%d: Dog {barks: 2}}: - assume ((%d::bark) == "Bark! Bark!") + with {$d: Dog {barks: 2}}: + assume (($d|bark) == "Bark! Bark!") -(my action %actions %body) compiles to: - lua> "\ - ..local fn_name = \%actions[1].stub:as_lua_id() - local \%args = List(\%actions[1]:get_args()) - table.insert(\%args, 1, \(\%me)) - local lua = LuaCode("class.", fn_name, " = ", \(what (%args -> %body) compiles to)) - for i=2,#\%actions do - local alias = \%actions[i] +(my action $actions $body) compiles to: + lua> " + local fn_name = \$actions[1].stub:as_lua_id() + local \$args = List(\$actions[1]:get_args()) + table.insert(\$args, 1, \(\$me)) + local lua = LuaCode("class.", fn_name, " = ", \(what ($args -> $body) compiles to)) + for i=2,#\$actions do + local alias = \$actions[i] local alias_name = alias.stub:as_lua_id() - local \%alias_args = List(alias:get_args()) - table.insert(\%alias_args, 1, \(\%me)) + local \$alias_args = List(alias:get_args()) + table.insert(\$alias_args, 1, \(\$me)) lua:add("\\nclass.", alias_name, " = ") - if \%args == \%alias_args then + if \$args == \$alias_args then lua:add("class.", fn_name) else - lua:add(\(what (%alias_args -> %actions.1) compiles to)) + lua:add(\(what ($alias_args -> $actions.1) compiles to)) end end return lua" -(object %classname extends %parent %class_body) compiles to: - unless (%classname.type == "Action"): - compile error at %classname "\ - ..Expected this to be an action, not a \%classname.type" +(object $classname extends $parent $class_body) compiles to: + unless ($classname.type == "Action"): + compile error at $classname \ + .."Expected this to be an action, not a \$classname.type" - for % in %classname: - unless (% is text): - compile error at % "Class names should not have arguments." + for $ in $classname: + unless ($ is text): + compile error at $ "Class names should not have arguments." return (..) - Lua "\ - ..do - local class = {name=\(quote %classname.stub)} + Lua " + do + local class = {name=\(quote $classname.stub)} class.__type = class.name setmetatable(class, { - __index=\(%parent as lua expr), + __index=\($parent as lua expr), __tostring=function(cls) return cls.name end, __call=function(cls, inst) if inst == nil then return cls end @@ -105,11 +105,11 @@ test: class.__tostring = function(inst) return inst.name..getmetatable(Dict{}).__tostring(inst) end - \(%class_body as lua) + \($class_body as lua) for stub,metamethod in pairs(globals.METAMETHOD_MAP) do class[metamethod] = class[stub:as_lua_id()] end end" -(object %classname %class_body) parses as (..) - object %classname extends (nil) %class_body +(object $classname $class_body) parses as (..) + object $classname extends (nil) $class_body @@ -1,25 +1,25 @@ -#!/usr/bin/env nomsu -V4.12.12.8 +#!/usr/bin/env nomsu -V5.12.12.8 # This file defines some actions that interact with the operating system and filesystem. test: assume (nomsu files for "core") -externally (files for %path) means: - %files = (=lua "Files.list(\%path)") - if %files: - %files = (List %files) - return %files +externally (files for $path) means: + $files = (=lua "Files.list(\$path)") + if $files: + $files = (List $files) + return $files -externally (nomsu files for %path) means: - for %nomsupath in (%package.nomsupath::all matches of "[^;]+"): - %files = (files for "\(%nomsupath)/\%path") - if %files: - return %files +externally (nomsu files for $path) means: + for $nomsupath in ($package.nomsupath|all matches of "[^;]+"): + $files = (files for "\($nomsupath)/\$path") + if $files: + return $files -externally (sh> %cmd) means: - lua> "\ - ..local result = io.popen(\%cmd) +externally (sh> $cmd) means: + lua> " + local result = io.popen(\$cmd) local contents = result:read("*a") result:close() return contents" @@ -27,27 +27,24 @@ externally (sh> %cmd) means: test: read file "lib/os.nom" -externally (read file %filename) means (=lua "Files.read(\%filename)") +externally (read file $filename) means (=lua "Files.read(\$filename)") externally [..] - write to file %filename %text, to file %filename write %text - write %text to file %filename + write to file $filename $text, to file $filename write $text + write $text to file $filename ..all mean: - assume (%filename != "stdin") or barf "Cannot write to stdin" - lua> "\ - ..local file = io.open(\%filename, 'w') - file:write(\%text) - file:close()" + assume ($filename != "stdin") or barf "Cannot write to stdin" + lua> "local file = io.open(\$filename, 'w')\nfile:write(\$text)\nfile:close()" -externally (source lines of %tree) means: - %source = (%tree.source if (%tree is syntax tree) else %tree) - %file = (read file %source.filename) +externally (source lines of $tree) means: + $source = ($tree.source if ($tree is syntax tree) else $tree) + $file = (read file $source.filename) return (..) [..] : - for % in (%file::line number at %source.start) to (..) - %file::line number at %source.stop - ..: add (%file::line %) - ..::joined with "\n" + for $ in ($file|line number at $source.start) to (..) + $file|line number at $source.stop + ..: add ($file|line $) + ..|joined with "\n" -externally (spoof file %text) means (%Files.spoof %text) -externally (spoof file %filename = %text) means (%Files.spoof %filename %text) +externally (spoof file $text) means ($Files.spoof $text) +externally (spoof file $filename = $text) means ($Files.spoof $filename $text) diff --git a/lib/things.nom b/lib/things.nom index c7ff2d6..de51683 100644 --- a/lib/things.nom +++ b/lib/things.nom @@ -1,140 +1,137 @@ -#!/usr/bin/env nomsu -V4.12.12.8 +#!/usr/bin/env nomsu -V5.12.12.8 # A library for simple object oriented programming. test: an (Empty) is a thing a (Dog) is a thing: - [%it, %its] = [Dog, Dog] - (%its::set up) means: - %its.barks or= 0 + [$it, $its] = [Dog, Dog] + ($its|set up) means: + $its.barks or= 0 - [%its::bark, %its::woof] all mean: - %barks = [: for % in 1 to %its.barks: add "Bark!"] - return (%barks::joined with " ") + [$its|bark, $its|woof] all mean: + $barks = [: for $ in 1 to $its.barks: add "Bark!"] + return ($barks|joined with " ") - (%it::gets pissed off) means: %it.barks += 1 + ($it|gets pissed off) means: $it.barks += 1 (Dog).genus = "Canus" - %d = (a Dog with {barks: 2}) - assume "\%d" == "Dog {barks: 2}" - assume (type of %d) == "Dog" - assume (%d is a "Dog") - assume %d.barks == 2 - assume ((%d::bark) == "Bark! Bark!") - assume ((%d::woof) == "Bark! Bark!") - %d::gets pissed off - assume (%d.barks == 3) - assume ((%d::bark) == "Bark! Bark! Bark!") - assume (%d.genus == "Canus") - assume ("\(%d.class)" == "Dog") - assume (%d.genus == "Canus") - assume (%d.barks == 3) - %d2 = (a Dog) - assume (%d2.barks == 0) or barf "Default initializer failed" - with {%d: a Dog with {barks: 1}}: - assume ((%d::bark) == "Bark!") + $d = (a Dog with {barks: 2}) + assume "\$d" == "Dog {barks: 2}" + assume (type of $d) == "Dog" + assume ($d is a "Dog") + assume $d.barks == 2 + assume (($d|bark) == "Bark! Bark!") + assume (($d|woof) == "Bark! Bark!") + $d|gets pissed off + assume ($d.barks == 3) + assume (($d|bark) == "Bark! Bark! Bark!") + assume ($d.genus == "Canus") + assume ("\($d.class)" == "Dog") + assume ($d.genus == "Canus") + assume ($d.barks == 3) + $d2 = (a Dog) + assume ($d2.barks == 0) or barf "Default initializer failed" + with {$d: a Dog with {barks: 1}}: + assume (($d|bark) == "Bark!") a (Corgi) is a thing: - [%it, %its] = [Corgi, Corgi] - %it [set up, gets pissed off] like a (Dog) - (%it::as text) means "Dogloaf \{: for %k = %v in %it: add %k = %v}" - (%its::sploot) means "sploooot" - [%its::bark, %its::woof] all mean: - %barks = [: for % in 1 to %its.barks: add "Yip!"] - return (%barks::joined with " ") + [$it, $its] = [Corgi, Corgi] + $it [set up, gets pissed off] like a (Dog) + ($it|as text) means "Dogloaf \{: for $k = $v in $it: add $k = $v}" + ($its|sploot) means "sploooot" + [$its|bark, $its|woof] all mean: + $barks = [: for $ in 1 to $its.barks: add "Yip!"] + return ($barks|joined with " ") - %corg = (a Corgi) - assume (%corg.barks == 0) - assume "\%corg" == "Dogloaf {barks: 0}" - with {%d: a Corgi with {barks: 1}}: - assume ((%d::sploot) == "sploooot") or barf "subclass method failed" - assume ((%d::bark) == "Yip!") or barf "inheritance failed" - assume ((%d::woof) == "Yip!") + $corg = (a Corgi) + assume ($corg.barks == 0) + assume "\$corg" == "Dogloaf {barks: 0}" + with {$d: a Corgi with {barks: 1}}: + assume (($d|sploot) == "sploooot") or barf "subclass method failed" + assume (($d|bark) == "Yip!") or barf "inheritance failed" + assume (($d|woof) == "Yip!") - with {%d: a Dog with {barks: 2}}: - assume ((%d::bark) == "Bark! Bark!") + with {$d: a Dog with {barks: 2}}: + assume (($d|bark) == "Bark! Bark!") a (Vec) is a thing with {x, y}: - %its = (Vec) - (%its::+ %other) means (Vec {x: %its.x + %other.x, y: %its.y + %other.y}) + $its = (Vec) + ($its|+ $other) means (Vec {x: $its.x + $other.x, y: $its.y + $other.y}) assume ((Vec {x: 1, y: 2}) + (Vec {x: 10, y: 10})) == (Vec {x: 11, y: 12}) assume (((Vec {x: 1, y: 2}) + (Vec {x: 10, y: 10})) != (Vec {x: 0, y: 0})) [..] - %it can %actions like a %class, %it can %actions like an %class - %it has %actions like a %class, %it has %actions like an %class - %it %actions like a %class, %it %actions like an %class + $it can $actions like a $class, $it can $actions like an $class + $it has $actions like a $class, $it has $actions like an $class + $it $actions like a $class, $it $actions like an $class ..all compile to: - %lua = (Lua "") - %class_expr = (%class as lua expr) - %lines = [] - for %a in %actions: - %lines::add "\ - ..\(%it as lua expr).\(%a.stub::as lua id) = \%class_expr.\(%a.stub::as lua id)" - %lua::add %lines joined with "\n" - return %lua + $lua = (Lua "") + $class_expr = ($class as lua expr) + $lines = [] + for $a in $actions: + $lines| + add "\($it as lua expr).\($a.stub|as lua id) = \$class_expr.\($a.stub|as lua id)" + $lua|add $lines joined with "\n" + return $lua -%METAMETHOD_MAP = {..} +$METAMETHOD_MAP = {..} "as text": "__tostring", "clean up": "__gc", "+": "__add", "-": "__sub" "*": "__mul", "/": "__div", negative: "__unm", "//": "__idiv", mod: "__mod" "^": "__pow", "&": "__band", "|": "__bor", "~": "__bxor", "~": "__bnot" "<<": "__bshl", ">>": "__bshr", "==": "__eq", "<": "__lt", "<=": "__le" "set 1 =": "__newindex", size: "__len", iterate: "__ipairs", "iterate all": "__pairs" -((% as text like a dict)'s meaning) = ({}'s metatable).__tostring -externally (a class named %classname with %members ((initialize %it)'s meaning)) \ +(($ as text like a dict)'s meaning) = ({}'s metatable).__tostring +externally (a class named $classname with $members ((initialize $it)'s meaning)) \ ..means: - %class = {__type: %classname} - %class.__index = %class - %class.class = %class - %class.__tostring = (% -> "\(%.__type) \(% as text like a dict)") - %class.__eq = ({}'s metatable).__eq - %class.__len = ({}'s metatable).__len - if %members: - %class.__members = %members - %class.__newindex = (..) - for (%its %key = %value): - if %members.%key: - rawset %its %key %value + $class = {__type: $classname} + $class.__index = $class + $class.class = $class + $class.__tostring = ($ -> "\($.__type) \($ as text like a dict)") + $class.__eq = ({}'s metatable).__eq + $class.__len = ({}'s metatable).__len + if $members: + $class.__members = $members + $class.__newindex = (..) + for ($its $key = $value): + if $members.$key: + rawset $its $key $value ..else: - barf "Cannot set \%key, it's not one of the allowed member fields." + barf "Cannot set \$key, it's not one of the allowed member fields." - set %class's metatable to {..} - __tostring: %class -> %class.__type - __call: for (%class with %initial_values): - if (%initial_values == (nil)): return %class - set %initial_values's metatable to %class - if %initial_values.set_up: - %initial_values::set up - return %initial_values + set $class's metatable to {..} + __tostring: $class -> $class.__type, __call: for ($class with $initial_values): + if ($initial_values == (nil)): return $class + set $initial_values's metatable to $class + if $initial_values.set_up: + $initial_values|set up + return $initial_values if ((initialize)'s meaning): - initialize %class - for %stub = %metamethod in %METAMETHOD_MAP: - if %class.(%stub::as lua id): - %class.%metamethod = %class.(%stub::as lua id) + initialize $class + for $stub = $metamethod in $METAMETHOD_MAP: + if $class.($stub|as lua id): + $class.$metamethod = $class.($stub|as lua id) - return %class + return $class [..] - a %classname is a thing with %members %class_body - an %classname is a thing with %members %class_body + a $classname is a thing with $members $class_body + an $classname is a thing with $members $class_body ..all compile to: - %class_id = (%classname.stub::as lua id) - if %class_body: - %body_lua = (%class_body as lua) - %body_lua::remove free vars [%class_id] - %body_lua::declare locals + $class_id = ($classname.stub|as lua id) + if $class_body: + $body_lua = ($class_body as lua) + $body_lua|remove free vars [$class_id] + $body_lua|declare locals return (..) - Lua "\ - ..\%class_id = a_class_named_1_with(\(quote %classname.stub), \(%members as lua)\(..) - (Lua ", function(\%class_id)\n \%body_lua\nend") if %class_body else "" + Lua " + \$class_id = a_class_named_1_with(\(quote $classname.stub), \($members as lua)\((Lua ", function(\$class_id)\n \$body_lua\nend") if $class_body else "")\ ..) - a_\%class_id = function(initial_values) return \(%classname.stub::as lua id)(initial_values or {}) end - an_\%class_id, a_\(%class_id)_with, an_\(%class_id)_with = \ - ..a_\%class_id, a_\%class_id, a_\%class_id" + a_\$class_id = function(initial_values) return \($classname.stub|as lua id)(initial_values or {}) end + an_\$class_id, a_\($class_id)_with, an_\($class_id)_with = a_\$class_id, a_\$class_id, a_\$class_id" -[a %classname is a thing %class_body, an %classname is a thing] all parse as (..) - a %classname is a thing with (nil) %class_body +[a $classname is a thing $class_body, an $classname is a thing] all parse as (..) + a $classname is a thing with (nil) $class_body |
