Skip to content

Instantly share code, notes, and snippets.

@hUwUtao
Last active June 14, 2023 17:30
Show Gist options
  • Save hUwUtao/5c14ac3bc76275bc21137c227a2a9c6e to your computer and use it in GitHub Desktop.
Save hUwUtao/5c14ac3bc76275bc21137c227a2a9c6e to your computer and use it in GitHub Desktop.
A Turing's machine compatible language in mind
// base language
// value
// if start with 0-9 then will be parse to number
// if start with [ then the very next line will be the value
// if line start with | then try to pipe the next value until EOL (apply to text have space)
// else will find until a valid value (charCode >= 64), end with space
// then it will try to find comparision keyword l(eq, gr, ge, lr, le)
state = 3
helth = 3
ent@hit // ^ > it
he a= it.tar.mod.el // #ent@hit#he will be resolve to #ent@hit#it#tar.mod.el
// auto if
he.element eq fire // closure 0
// func
it.dmgBy helth
// leaked
it.dying // closure 1
it.tar.len gr 0 // closure 0 of closure 1
// seal
it.tar.each // closure 0 of closure 0 of closure 1
it.reward 3
// A mail to myself, nvm about it: #ent@hit#ent@hit@it.dying1#ent@hit@it.tar.each#ent@hit@it.reward@it
// unseal
!^ // closure 1 of closure 1
it.heal it.healthCap
// leaked
// compiled
SET #state 3
SET #helth 3
DISPATCH
:ent.hit LEAK
SET #ent@hit#it ^ // sealed
LEQ #ent@hit#it.tar.mod.el.element "fire" // leaked
CFI #ent@hit#0
LEQ #ent@hit#it.dying 1 // leaked
CFI #ent@hit#1 // leaked
:#ent@hit#0
#ent@hit#it.dmgBy(#helth)
:#ent@hit#1 // leaked
LGR #ent@hit#it.tar.len 0 // leaked
SEAL // SET #ent@hit#1#seal ^
CFI #ent@hit#1#0 // leaked
UNSEAL // SET ^ #ent@hit#1#seal
INV
CFI #ent@hit#1#1
:#ent@hit#1#0 // leaked
MAP #ent@hit#it.tar #ent@hit#1#0#0 // leaked
:#ent@hit#1#0#0 LEAK
^.reward(3)
:#ent@hit#1
#ent@hit#it.heal #ent@hit#it.healthCap
// fine asm (still readable, in form of macro? idk why does this even exist)
set 0 3
set 1 3
:ent@hit
set 2 b
leq 2.tar.mod.el.element "fire"
cci 0
leq 2.dying 1
cci 1
:#ent@hit#0
2.dmgBy(#1)
:#ent@hit#1
lgr 2.tar.len 0
set 3 b
cci 0
set b 3
inv
cci 1
:#ent@hit#1#0
map 2.tar #ent@hit#1#0#0
:#ent@hit#1#0#0
^.reward(3)
:#ent@hit#1#1
2.heal(2.healthCap)
// asm
set 0 3
set 1 3
dispatch ent.hit 3
set 2 b // 3
leq 2.tar.mod.el.element "fire"
mov 9
leq 2.dying 1
mov 11
eof
2.dmgBy(#1) // 9
eof
lgr 2.tar.len 0 // 11
cut 3 b
mov 18
set b 3
inv
mov 20
eof
map 2.tar 20 // 18
eof
^.reward(3) // 20
eof
2.heal(2.healthCap) // 20
eof
// explain: leak meant buffer being overwritten, cannot be use for operation in the same function
// operations that leak: LEQ MAP FILTER INV
// the leak function: Leaked function contain leaked operation. `:function LEAK` will force the compiler not to seal (overriden by operations that take functions: MAP, FILTER, ...)
// seal will copy buffer into temporary memory then release once leaked closure is done
// base operation
set a b - Copy POINTER from a to b
l(eq, gr, ge, lr, le) a b - Compare and write to buffer
map/fil a f - Array operation use function
sli a b - Array operation use values
// machine prototype
SEAL/UNSEAL - move buffer's pointer to a temporary variable, then dump the buffer's pointer. unseal do the opposite
// asm like
cut a b - mov but empty a
// fine asm subset
cci - Conditional closure
// asm subset
mov ln - Move to line?, will continue next to this operation if eof provided
eol - mov to the mov
dispatch - expose sharpless function
// TLDR: A language interperter directly into Turing's machine, idk how
// In theory: this language is fast af, however this is almost a JIT language that require a VM like Lua, but you can build it statically by create a fixed size array of operations instead of a vector of operations.
// It is a functional oriented language.
// Cons:
// - compile with your brain
// - execute with your brain
// - recursive is not tested
// Think again, swapping constantly hurt the performance, init?
// I wrote this while drunk. I don't know why, but it's interesting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment