Git Product home page Git Product logo

slothlang's Introduction

SlothLang

SlothLang

Build Status MIT Licence

SlothLang is an esoteric programming language by Aaron Goidel

Features

  • Write code in a highly efficient and easy to read language
  • Slothy sloths are slothy

Tech

SlothLang is parsed and executed in C.

And of course the code behind the SlothLang VM itself is open source and can be found on GitHub.

Usage

A Sloth program is parsed as new-line deliminated instructions. Every line starts a new instruction at 0x00. Each occurrence of the word sloth on a line increases the instruction code by one. At the end of each line the resulting instruction code is pushed and the next line is read.

Since a Sloth command is generally based on the number of times the word sloth appears in a row, the syntax will be documented as a multiplication. For example the documentation sloth * 3 means sloth sloth sloth in Sloth code.

To save time and effort, there are a few commands which do not follow the scheme outlined above. These will be outlined below.

Note: the and operator is used to separate arguments.

Syntax and Effects

Exit

Syntax: nap
Effect: will terminate the execution of the program and return the top element from the stack.
NOTE: every Sloth file must end in nap.

Add

Syntax: sloth * 2
Effect: pops the first two values off the stack and pushes their sum.
Stack: S, x, y -> S, x+y

Subtract

Syntax: sloth * 3
Effect: pops the first two values off the stack and pushes their difference.
Stack: S, x, y -> S, x-y

Multiply

Syntax: sloth * 4
Effect: pops the first two values off the stack and pushes their product.
Stack: S, x, y -> S, x*y

Divide

Syntax: sloth * 5
Effect: pops the first two values off the stack and pushes their quotient.
Stack: S, x, y -> S, x/y
NOTE: Division in SlothLang is integer division, meaning divide will always round fractions down. e.g. 3/2 = 1

Compare <c>

Syntax: sloth * 6 and sloth * c

Notice that the compare instruction requires an argument. The number of sloths after the and will determine which comparison should be made. See Comparison Codes for reference.

Effect: pops the first two values off the stack and pushes the truthiness of a comparison between them.
Stack: S, x, y -> S, 1 if true 0 if false

Input <t>

Syntax: sloth * 7 and sloth * t

The input instruction takes a type code to determine what kind of data is being read. See Type Codes for reference.

Effect: reads in either an integer or an ASCII character from standard in.
Stack: S -> S, x

Output <t>

Syntax: sloth * 8 and sloth * t

The output instruction takes a type code to determine what kind of data is being displayed. See Type Codes for reference.

Effect: pops the top value off the stack and writes it to standard out.
Stack: S, x -> S

GOTO <n>

Syntax: sloth * 9 and sloth * n

The GOTO instruction takes a number of sloths as the destination if the result is true.

Effect: pops the top value off the stack, if the value is 1, the program counter is set to specified instruction, else continues as normal.
Stack: S, x -> S

Push <i>

Syntax: slothy sloth * i
Effect: pushes the integer value of the number of sloths following slothy onto the stack.
Stack: S -> S, x
Example: slothy sloth sloth sloth pushes 3 onto the stack.

Duplicate

Syntax: sloth * 10
Effect: pops an element off the stack and pushes it twice.
Stack: S, x -> S, x, x

Operation, Comparison, and Type Codes

SlothLang relies on the translation of a number of sloths to a numeric code in order to perform specific operations.

Comparison Codes

The Compare function uses <c> sloths in order to select what kind of comparison is being made.

Comparison Code Operation
0x01 x == y
0x02 x != y
0x03 x < y
0x04 x <= y
0x05 x > y
0x06 x >= y

Type Codes

Type Codes <t> are used in the Input and Output instructions in order to determine what kind of data is being read or written.

Type Code Type of I/O
0x01 A signed integer value
0x02 A single ASCII character

Operation Codes

Sloth code is read in by the SlothVM as bytecode. The following is the bytecode for each SlothLang instruction.

Byte Code Name
0x00 Exit
0x01 Push <i>
0x02 Add
0x03 Subtract
0x04 Multiply
0x05 Divide
0x06 Compare <c>
0x07 Input <t>
0x08 Output <t>
0x09 GOTO <o>
0x0A DUP

License

This project is licensed under the MIT License - see the LICENSE file for details

Thanks To

  • Mariana Ortiz Luna for the awesome logo

slothlang's People

Contributors

aaroncgoidel avatar bakoushin avatar carewdavid avatar erin-sparkbox avatar pranavbhatia avatar wgoodall01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

slothlang's Issues

Proof Read/Edit Documentation

In order to make SlothLang more accessible, documentation is key. This issue is for anyone who wants to help edit the docs. Whether it be typo fixes, formatting, or new information, all help is welcome.

Write example programs

Currently, the only SlothLang program is HelloWorld. SlothLang could use some fun and interesting programs to show it off.

SlothLang not Turing Complete?

It seems like SlothLang programs are pushdown automata, not turing machines, which limits the possible programs that can be written.

The only memory available to programs is the stack, and the targets of all gotos must be specified absolutely in the code, meaning that programs can only have a finite number of states, which fits the description in the linked article.

GOTO causes a seg fault

There seems to be an issue with the GOTO command causing a segmentation fault when executed. I believe there is an error in setting the program counter.

Improve Parser

As of right now, the parser gets thrown off by whitespace in programs. The parser should just ignore extraneous whitespace. All in all, I think the parser should be a bit more robust and can be improved upon greatly.

Improve CI and Unit Testing

Any help with adding test cases to ensure new edits to the SlothVM and parser continue to work as expected is welcome.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.