btwael / mammouth

Unfancy PHP
http://mammouth.boutglay.com
MIT License
214 stars 22 forks source link

v4 eta? #83

Closed aolko closed 5 years ago

aolko commented 6 years ago

it's been 3 years,please give us the eta

btwael commented 6 years ago

I'm working on it, but the development is too slow since I have to maintain other projects some of them are commercial so I can sponsore mammouth and other interesting open soure project to come. When I developed mammouth I was a high school student and then at college. Now I'm a master student, I have less time to code. But hopefully, the next version will be amazing.

jots commented 6 years ago

looking forward to it! amazing is amazing!

btwael commented 6 years ago

I want just to tell you that I'm working on version 4, and one of the new feature is optional typing to make debugging easier and optimize output php code, this allowed to add object-oriented style for native type like array.

example:

Array m = []
m.push(12)

will be compiled to

$m = array();
array_push($m, 12);

What do you think?

aolko commented 6 years ago

maybe

prezire commented 6 years ago

That's going to take you a century to finish with all of PHP's helper functions. How about doing something like below instead? Pretty sure class visibility and void will be widely accepted by then, by the time you're done. Very nice work on mammouth though!

php declare strict = true
  namespace Company\Tests
    #@protected  Class scopes were recently proposed.
    protected class Test

      #private $sName;
      private sName

      #public function __construct($name:string);
      __construct (name:string) ->
        @setName name
        static::greetMsg @getName()

      #public function setName($name:string):void;
      setName:void (name:string) ->
        @sName = name
        return

      #public function getName():string;
      getName:string -> @sName

      #public static function greet():string;      
      static greet:string -> 'hello world'

      #protected static function greetMsg($msg:string);
      protected static greetMsg:void (msg:string) ->
        echo "hello #{msg}"
        return

      #public static somethingMixed(). 
      #Returns an empty mixed object type. PHP has no object type.
      static somethingMixed -> (object)[]

use Company\Tests\Test as T
t:T = new T 'some name'
echo t.getName()
echo T::greet()
var_dump T::somethingMixed()
btwael commented 6 years ago

@prezire, thank you for your suggestion, as I announced before in this thread I'm working the v4 now. The solution that I implemented the v4 to solve that for the moment is something like this:

native("array_push($1, $2)", arr, el)

and it will be compiled to something like this:

<?php
array_push($arr, $el);
?>

This may allow to call php helper function with less confusion for the compiler, but this give an interesting result with other features like function/method inlining that I also implemented in this version.

Let's me clear the idea, in this version we will have an sdk, which is a collection of predefined class and methods to be used within Mammouth, let me give you an example

class Array
  public fn add(element) inline ->
    native("array_push($1, $2)", this, element)
  public fn removeLast inline ->
    native("array_pop($1)", this)
  public int get length() inline ->
    native("count($1)", this)
  public fn operator[](int index) inline ->
    native("$1[$2]", this, index)

So if you write something like:

Array arr = []
arr.add(12)

it will output

$arr = array();
array_push($arr, 12);

This will make coding in mammouth easier and probably implementing autocompletion in IDE also will be easier.

Remark: The typing is optional, we also have method overloading and operator overloading, we may also add a package manager to support including external mammouth libraries but also OOP wrapper for helper function.

What do you think about all that?

prezire commented 6 years ago

Looks good.

btwael commented 5 years ago

I just published the source code for the fourth version, it was too long and hard to develop it; It's an undocumented beta version, with error reporting to be improved.

A package manager is being developed too.

You can check the website of the beta version at http://mammouth.boutglay.com/beta/

Thank you