GithubHelp home page GithubHelp logo

tsujp / pocketlang Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thakeenathees/pocketlang

0.0 1.0 0.0 1.58 MB

A small and fast programming language.

Home Page: https://thakeenathees.github.io/pocketlang/

License: MIT License

Python 3.83% C 93.66% Ruby 0.26% Batchfile 1.15% Makefile 0.31% JavaScript 0.46% Lua 0.33%

pocketlang's Introduction

Pocketlang is a small (~3000 semicolons) and fast functional language written in C. It's syntactically similar to Ruby and it can be learned within 15 minutes. Including the compiler, bytecode VM and runtime, it's a standalone executable with zero external dependencies just as it's self descriptive name. The pocketlang VM can be embedded in another hosting program very easily.

Wren Language and their wonderful book Crafting Interpreters were used as a reference to write this language.

What pocketlang looks like

# Python like import statement.
from lang import clock as now

# A recursive fibonacci function.
def fib(n)
  if n < 2 then return n end
  return fib(n-1) + fib(n-2)
end

# Prints all fibonacci from 0 to 10 exclusive.
for i in 0..10
  print(fib(i))
end

Try It Now

You can try pocketlang on your browser. It's a WebAssembly build of the VM compiled using emscripten. Note that in the webassembly version of the language, some features (input, file handling, relative import, etc.) have disabled, has limited memory allocations, and the stdout calls might be slower.

Documentation

The pocketlang documentation is hosted at https://thakeenathees.github.io/pocketlang/ which is built from the docs branch generated by a little python script at docs/generate.py. Note that the documentations are WIP and might not be up to date.

Performance

Pocketlang supports tail call optimization. When a function returns a call, the callee can re-use the caller's stack frame, this will optimize memory from O(n) to O(1) and for tail recursive it'll completely prevent stackoverflows and yet it's faster than tco disabled.

All benchmarks below were executed on: Windows10 (64bit), ASUS N552VX, Intel Core i7-6700HQ 2.6GHz with 12GB SODIMM Ram. And the language versions are: pocketlang (pre-alpha), wren v0.3.0, python v3.7.4, ruby v2.7.2.

preformance

The source files used to run benchmarks can be found at test/benchmarks/ directory. They were executed using a small python script in the test directory.

Building From Source

It can be build from source easily without any dependencies, or additional requirements except for a c99 compatible compiler. It can be compiled with the following command.

GCC / MinGw / Clang (alias with gcc)

gcc -o pocket cli/*.c src/*.c -Isrc/include -lm

MSVC

cl /Fepocket cli/*.c src/*.c /Isrc/include && rm *.obj

Makefile

make

To run make file on windows with mingw, you require make and find unix tools in your path. Which you can get from msys2 or cygwin. Run set PATH=<path-to-env/usr/bin/>;%PATH% && make, this will override the system find command with unix find for the current session, and run the make script.

Windows batch script

build

You don't have to run the script from a Visual Studio .NET developer command prompt, It'll search for the MSVS installation path and setup the build environment.

For other compiler/IDE

  1. Create an empty project file / makefile.
  2. Add all C files in the src directory.
  3. Add all C files in the cli directory (NOT recursively).
  4. Add src/include to include path.
  5. Compile.

If you weren't able to compile it, please report us by opening an issue.

References

pocketlang's People

Contributors

alexcpatel avatar comonadd avatar ekinbarut avatar lukeed avatar naurelius avatar ntnlabs avatar rhnsharma avatar takashiidobe avatar thakeenathees avatar tiagocavalcante avatar timwi avatar tsujp avatar xsavitar avatar

Watchers

 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.