Front Page All Articles Recent Changes Random Article

Contents

Concatenative language

  • ACL
  • Ait
  • Aocla
  • Breeze
  • Callisto
  • Cat
  • Cognate
  • colorForth
  • Concata
  • CoSy
  • Deque
  • DSSP
  • dt
  • Elymas
  • Enchilada
  • ETAC
  • F
  • Factor
  • Fiveth
  • Forth
  • Fourth
  • Freelang
  • Gershwin
  • hex
  • iNet
  • Joy
  • Joy of Postfix App
  • kcats
  • Kitten
  • lang5
  • Listack
  • LSE64
  • Lviv
  • Meow5
  • min
  • Mirth
  • mjoy
  • Mlatu
  • Ode
  • OForth
  • Om
  • Onyx
  • Plorth
  • Popr
  • Porth
  • PostScript
  • Prowl
  • Quest32
  • Quackery
  • r3
  • Raven
  • Retro
  • RPL
  • SPL
  • Staapl
  • Stabel
  • Tal
  • Titan
  • Trith
  • Uiua
  • Worst
  • xs
  • XY
  • 5th
  • 8th

Concatenative topics

  • Compilers
  • Interpreters
  • Type systems
  • Object systems
  • Quotations
  • Variables
  • Garbage collection
  • Example programs

Concatenative meta

  • People
  • Communities

Other languages

  • APL
  • C++
  • Erlang
  • FP trivia
  • Haskell
  • Io
  • Java
  • JavaScript
  • Lisp
  • ML
  • Oberon
  • RPL
  • Self
  • Slate
  • Smalltalk

Meta

  • Search
  • Farkup wiki format
  • Etiquette
  • Sandbox

Meow5

Meow5 is a programming language experiment written in NASM assembly and targeting 32-bit i386 Linux. Its syntax is very similar to Forth.

It is "concatenative" in two senses:

  • In the usual program composition sense (see Concatenative language)
  • In the unusual sense of using inlined machine code to concatenate programs from smaller functional units

Meow5 can run programs in the interpreter interactively and can also write those programs (or any named portion of them) to disk as stand-alone Linux ELF executables.

Example

This example shows two defined routines: meow prints a "Meow!" with newline, meow5 is composed of five calls to meow. This interactive session shows both the programmer's input and the result:

def meow "Meow!\n" print ;

meow
Meow!

def meow5 meow meow meow meow meow ;

meow5
Meow!
Meow!
Meow!
Meow!
Meow!

Meow5 can be asked to "inspect" the "defs" (definitions) by name:

inspect meow
meow: 45 bytes IMMEDIATE COMPILE
    e8 7 0 0 0 4d 65 6f 77 21 a 0 58 50 50 58 b9 0 0 0 0 80 3c 8 0 74 3 41 eb
f7 51 5a 59 bb 1 0 0 0 b8 4 0 0 0 cd 80

inspect meow5
meow5: 225 bytes IMMEDIATE COMPILE
    e8 7 0 0 0 4d 65 6f 77 21 a 0 58 50 50 58 b9 0 0 0 0 80 3c 8 0 74 3 41 eb
f7 51 5a 59 bb 1 0 0 0 b8 4 0 0 0 cd 80 e8 7 0 0 0 4d 65 6f 77 21 a 0 58 50 50
58 b9 0 0 0 0 80 3c 8 0 74 3 41 eb f7 51 5a 59 bb 1 0 0 0 b8 4 0 0 0 cd 80 e8 7
0 0 0 4d 65 6f 77 21 a 0 58 50 50 58 b9 0 0 0 0 80 3c 8 0 74 3 41 eb f7 51 5a
59 bb 1 0 0 0 b8 4 0 0 0 cd 80 e8 7 0 0 0 4d 65 6f 77 21 a 0 58 50 50 58 b9 0 0
0 0 80 3c 8 0 74 3 41 eb f7 51 5a 59 bb 1 0 0 0 b8 4 0 0 0 cd 80 e8 7 0 0 0 4d
65 6f 77 21 a 0 58 50 50 58 b9 0 0 0 0 80 3c 8 0 74 3 41 eb f7 51 5a 59 bb 1 0
0 0 b8 4 0 0 0 cd 80

The alarming output above is the raw i386 machine code of each definition. Upon closer inspection, you'll note that the contents of meow5 is precisely 5 concatenated copies of meow.

This program can be written to disk as a 317 byte Linux executable. (A looping version that produces the same output is a mere 160 bytes!)

Syntax and library

Meow5 has three syntactical rules:

  • Spaces separate tokens of input
  • Unless otherwise consumed by previous code (such as when compiling a new definition), tokens are assumed to be the name of a definition, looked up, and executed
  • Strings are enclosed in quotes ("foo"), escape sequences and interpolation are supported

The built-in library of defined routines is very small and contains a mixture of high-level and (extremely) low-level functionality, any of which can be replaced interactively.

The all definition lists all current definitions:

all
elf get set var loop? ? ? dup pop dec inc / * - + all inspect ps
printmode say print$ printnum number decimal bin oct hex radix str2num quote
num2str ; return def copystr get_token eat_spaces # get_input find is_runcomp
get_flags inline print strlen exit

Note that the # character is used as a comment, but it is not part of Meow5 syntax. Instead, it appears in the list of definitions above. A programmer can replace it or add other "syntactical" elements like it as desired.

External Links:

  • https://ratfactor.com/meow5/done - A guided tour
  • https://ratfactor.com/repos/meow5/ - The source as a Git repo

This revision created on Thu, 25 Apr 2024 18:56:42 by ratfactor (Added clarification)

Latest Revisions Edit

All content is © 2008-2024 by its respective authors. By adding content to this wiki, you agree to release it under the BSD license.