Giter VIP home page Giter VIP logo

tiny's Introduction

Tiny

Tiny is a small statically-typed language with an embeddable compiler and bytecode interpreter; it is designed to be easy to embed and does its best to avoid doing allocations/garbage collection.

// Reverse polish notation calculator

stack := array()

// The type of the 'stack' variable is inferred to be 'array'
// I can also explicitly specify it by doing
// stack: array = array(), but that's no fun

op := ""

// Constants
plus_op     :: '+'
minus_op    :: '-'
mul_op      :: '*'
div_op      :: '/'
print_op    :: "="
quit_op     :: "quit"

while op != quit_op {
    op = input()

    if stridx(op, 0) == plus_op { 
        array_push(stack, array_pop(stack) + array_pop(stack))
    } else if stridx(op, 0) == minus_op {
        array_push(stack, array_pop(stack) - array_pop(stack))
    } else if stridx(op, 0) == mul_op {
        array_push(stack, array_pop(stack) * array_pop(stack))
    } else if stridx(op, 0) == div_op {
        array_push(stack, array_pop(stack) / array_pop(stack))
    } else if op == print_op {
        print(array_pop(stack))
    } else if op != quit_op {
        array_push(stack, ston(op))
    }
}

Usage

You can use CMake to build a static library which you can integrate into your project like any other. Alternatively, you can just copy the few files inside include and src into your project.

Examples

Here are a few examples of how Tiny can be used.

Game Example

Alt text

I've written a small game which is scripted using Tiny. This example makes no use of garbage collection; in fact, there is no dynamic allocation being done in the scripts at all. You can find the code in the examples/game subdirectory of the repository. I made use of https://bitbucket.org/rmitton/tigr to facilitate the windowing, graphics and input.

Notice how every entity in the game has a Tiny_StateThread encapsulating its execution state. Since Tiny_StateThread is relatively lightweight, you can have hundreds, even thousands of them.

Text Editor Example

Alt text

I got carried away and wrote a vim-like text editor using this language. I wrote all the buffer manipulation and graphics code in C and then exposed an interface for the editor logic. Have a look at examples/notepad.

Multithreaded Web Server Example

I created a webserver which is capable of handling a large amount of concurrent connections with a variety of web application development utilities (async processing, routing, templating). Have a look at examples/server. I followed golang's "Writing Web Applications" tutorial which guides users through making a wiki and replicated that in tiny.

tiny's People

Contributors

goodpaul6 avatar

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.