A lightweight, fast embeddable scripting language.
Go to file
Thakee Nathees 2e7ede104d
Merge pull request #91 from ThakeeNathees/scons-removed
SConstruct file removed and build scripts refactored
2021-06-17 16:17:59 +05:30
.github/workflows Makefile: compile objects individually, then link 2021-06-17 00:56:09 -07:00
cli minor refactors for internal documenting. 2021-06-17 01:05:37 +05:30
docs changed the keyword in unit tests, prism and in the md 2021-06-16 11:14:35 +03:00
src minor refactors for internal documenting. 2021-06-17 01:05:37 +05:30
tests scons script removed and build scripts refactored 2021-06-17 16:13:47 +05:30
.gitignore scons script removed and build scripts refactored 2021-06-17 16:13:47 +05:30
AUTHORS AUTHORS: add alexcpatel to authors 2021-06-15 22:09:08 -07:00
build.bat scons script removed and build scripts refactored 2021-06-17 16:13:47 +05:30
LICENSE initial commit 2021-02-07 13:17:58 +05:30
Makefile Makefile: compile objects individually, then link 2021-06-17 00:56:09 -07:00
README.md Merge pull request #76 from ThakeeNathees/ci-workflow 2021-06-16 03:28:30 +05:30

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.

The language is written using Wren Language and their wonderful book Crafting Interpreters as a reference.

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 then tco disabled.

All the below benchmarks are ran 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 could be found at test/benchmarks/ directory. They were ran using a small python script in the test directory.

Building From Source

See build documentation for using an optional build script (Makefile, batch script for MSVC, SCons found in the build/ directory). 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

gcc -o pocket cli/*.c src/*.c -Isrc/include -lm -Wno-int-to-pointer-cast

MSVC

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

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 by opening an issue.

References