Skip to content

Releases: smuuf/primi

Primi 0.2

10 Oct 22:39
Compare
Choose a tag to compare

Primi 0.1

07 Oct 21:46
4c92e64
Compare
Choose a tag to compare

Simplified whole concept of Primi.

  • No more ambitions to make everything a 'object'.
  • No more ambitions to have prototypal or any other type of inheritance.
  • No more Lazy values.
  • No more value's methods and/or properties. These are now simple functions instead.
  • Uniform Function Call Syntax supported.
  • Extensions are applied during instantiation of interpreter.

Primi 0.0.15

24 Mar 12:46
6ef3f52
Compare
Choose a tag to compare
  • New: Support binding native PHP functions as Primi variables and/or functions

    • More of a "backend" feature.
    • Those who want to use Primi as library now can predefine functions that are to be available during the execution. These can be passed in as ordinary PHP closures (PHP callables will be internally converted to PHP closures).
    • New class FunctionContainer now acts as a universal wrapper for both standard Primi functions and also for newly supported native PHP functions. Note: Functions created from PHP callables won't have access to the caller context, but passing arguments from user-land to predefined native functions is fully supported.
    • Arguments are passed as Primi value objects (eg. \Smuuf\Primi\Structures\StringValue). A Primi value object is then also expected as the return value.
  • New: Array value now has 4 new methods:

    • array.copy() - Create a deep copy of the array.

    • array.shuffle() - Shuffle the array (existing array is shuffled, no new array is created and/or returned).

    • array.random() - Returns a random item from the array.

    • array.map(fn) - Returns a new array where the fn function was applied to all items.

      image

  • Change: Invoked functions now capture the context of where it was defined. Previous behavior was that the context of the caller was passed into the function.

Example of binding native PHP functions:

use \Smuuf\Primi\Context;
use \Smuuf\Primi\Structures\FunctionContainer;
use \Smuuf\Primi\Structures\StringValue;
use \Smuuf\Primi\Structures\FuncValue;

$c = new Context;

// Build function container from a native PHP anonymous function...
$fnContainer = FunctionContainer::buildNative(function($a, $b) {
    return new StringValue($a->getInternalValue() . "_" . $b->getInternalValue())
});

// Store the function value in the context as variable.
$c->setVariable('fun_fun', new FuncValue($fnContainer)));

// At this point the function "fun_fun" (which expects two arguments and returns a string)
// is available in user-land...

Primi 0.0.14

22 Mar 00:33
dc1a072
Compare
Choose a tag to compare
  • String, Number and Array value methods were externalized (refactored outside of their classes).
  • Each type of value can be extended (eg. by a developer using Primi as library for their own project) to register more extensions via ExtensionHub::register() method - register custom methods for each value type.
  • Libs most recently registered are used to lookup methods first.
    • Ie. Standard library methods can be easily overwritten, if the client wants/needs to.
  • Massive reduction of AST preprocessing (AST reduction) processing time.
Old New
█ (1 / 10) 
./sample/bench_all.primi ... 79.227 s
./sample/bench_simple.primi ... 8.047 s
█ (1 / 10) 
./sample/bench_all.primi ... 1.770 s
./sample/bench_simple.primi ... 4.005 s

Primi 0.0.13

13 Mar 00:53
Compare
Choose a tag to compare
  • Use own, improved version (fork) of php-peg.

Primi 0.0.12

17 Jan 22:17
Compare
Choose a tag to compare
  • Value objects now know how to represent themselves as strings in Primi syntax. (except functions)
  • Fix: Fixed bug when echoing array values in REPL mode.

Primi 0.0.11

16 Jan 01:14
49a4772
Compare
Choose a tag to compare
  • Functions are now Value objects (same as other values) and can now be stored and used as variables.
  • New: Support for anonymous functions.
    • Classic syntax: function(arg1, arg2) { return arg1 + arg2; }
    • Short syntax: (arg1, arg2) => { return arg1 + arg2; }
    • Higher order functions: ((fn, arg) => { return fn(arg); })((x) => { return x + 2;}, 8)
    • Direct invocation is supported: ((arg1, arg2) => { return arg1 + arg2; })(1, 2); returns 3

image

  • Improvements: Array definitions can have trailing commas.

Primi 0.0.10

04 Jan 12:00
Compare
Choose a tag to compare
  • "string" vs "number" comparison no longer throws an error.