bragful / ephp Goto Github PK
View Code? Open in Web Editor NEWBragful core: PHP Interpreter in pure Erlang
Home Page: https://bragful.com
License: GNU Lesser General Public License v2.1
Bragful core: PHP Interpreter in pure Erlang
Home Page: https://bragful.com
License: GNU Lesser General Public License v2.1
The original PHP stores the variables and adds a reference to them so, when an object, array or resource is assigned to a new variable, instead of a clone, it's copied a reference to the real data. In this way, the references are easier to handle internally and the weird behaviour for unset
is understood better.
At this moment the implementation for unset
is not compatible when we use it with objects because we're not destroying the object.
The return for atanh
in Erlang is based on the math C library and depending on the OS it is different even giving results. Because of that:
php_atanh(_Context, _Line, {_, Number}) ->
% math:atanh(Number); % FIXME: the implementation is not reliable
1 / 2 * math:log((1 + Number) / (1 - Number)).
Any idea? Should we have to keep it as is?
I'd like to write an adaptor by means of which ephp could be used as a rendering library for Phoenix / Raxx / Cowboy / whatever - but I noticed the LGPL license - 99% of Erlang/Elixir everything is Apache 2 licensed. I'm not sure what the implications of LGPL/Apache is but it could be a stumbling block.
Stackoverflow has some rambling description - but I think I need a flowchart to grok it ๐
Anyhow, my question is, considering you're the committer with the exception of a single commit, are you fully committed to LGPL or would you consider Apache 2 licensing?
It drops the following message in the compilation:
===> Compiling ephp
=ERROR REPORT==== 7-Jul-2017::20:12:40 ===
Error in process <0.327.0> with exit value:
{function_clause,
[{erl_parse,tokens,
[{bin,0,
[{bin_element,0,{integer,0,56},default,default},
{bin_element,0,{integer,0,46},default,default},
{bin_element,0,{integer,0,52},default,default},
{bin_element,0,{integer,0,48},default,default},
{bin_element,0,{integer,0,32},default,default},
{bin_element,0,{integer,0,50},default,default},
{bin_element,0,{integer,0,48},default,default},
{bin_element,0,{integer,0,49},default,default},
{bin_element,0,{integer,0,55},default,default},
{bin_element,0,{integer,0,45},default,default},
{bin_element,0,{integer,0,48},default,default},
{bin_element,0,{integer,0,49},default,default},
{bin_element,0,{integer,0,45},default,default},
{bin_element,0,{integer,0,49},default,default},
{bin_element,0,{integer,0,49},default,default}]},
[]],
[{file,"erl_parse.yrl"},{line,1432}]},
{epp,user_predef,2,[{file,"epp.erl"},{line,601}]},
{epp,init_server,4,[{file,"epp.erl"},{line,541}]}]}
===> Compiling src/ephp_parser.erl failed
src/ephp_parser.erl:none: internal error in parse_module;
crash reason: function_clause
in function erl_parse:tokens/2
called as erl_parse:tokens({bin,0,
[{bin_element,0,{integer,0,56},default,default},
{bin_element,0,{integer,0,46},default,default},
{bin_element,0,{integer,0,52},default,default},
{bin_element,0,{integer,0,48},default,default},
{bin_element,0,{integer,0,32},default,default},
{bin_element,0,{integer,0,50},default,default},
{bin_element,0,{integer,0,48},default,default},
{bin_element,0,{integer,0,49},default,default},
{bin_element,0,{integer,0,55},default,default},
{bin_element,0,{integer,0,45},default,default},
{bin_element,0,{integer,0,48},default,default},
{bin_element,0,{integer,0,49},default,default},
{bin_element,0,{integer,0,45},default,default},
{bin_element,0,{integer,0,49},default,default},
{bin_element,0,{integer,0,49},default,default}]},
[])
in call from epp:user_predef/2 (epp.erl, line 601)
in call from epp:init_server/4 (epp.erl, line 541)
make: *** [compile] Error 1
Watching var_dump
output I realize the number assigned to the instance is an unique ID for each running:
object(stdClass)#1 (2) {
["name"]=>
string(4) "John"
["surname"]=>
string(5) "Smith"
}
The number #1
is regarding to the ID. If we create another instance whatever the class came from the number is increased.
The use of and
and or
with the echo
and print
functions is tricky:
print "OK" or die("trying");
It could be understood as (1):
print("OK") or die("trying");
or maybe as (2):
print("OK" or die(trying));
The trade-off of the original line above is the ambiguity. The current implementation for PHP is the (1). And thanks to a work-around in the parser it is working for simple structures, but it should be improved.
At this moment, using PEG it's not possible to parse heredoc. Code as:
<?php
$data = <<<EOF
this is a free
text for be stored in \$data variable
EOF;
For PHP these numbers are identified by the PHP_INT_MIN
usually, but Erlang hasn't a limit for integers so, I did the implementation as:
to_int(infinity) -> -9223372036854775808;
to_int(nan) -> -9223372036854775808;
Maybe it should be fixed in another way (see ephp_data.erl
for further details).
out
variable from out = EphpContext.get_output(ctx)
contains hello worldthis is awesome
https://github.com/osbre/ephp_web/blob/main/lib/ephp_web/ephp_plug.ex#L34
getting an error ๐
** (CaseClauseError) no case clause matching: {:EXIT, {:function_clause, [{:ephp_interpr, :run, [#Reference<0.4106486204.4208197636.168118>, {:{}, [], [:print_text, "hello world\n", {{:line, 1}, {:column, 2}}]}, false], [file: ~c"/home/o/code/ephp_web/deps/ephp/src/ephp_interpr.erl", line: 77]}, {:lists, :foldl, 3, [file: ~c"lists.erl", line: 1350]}, {:ephp_interpr, :process, 3, [file: ~c"/home/o/code/ephp_web/deps/ephp/src/ephp_interpr.erl", line: 25]}, {:ephp, :eval, 3, [file: ~c"/home/o/code/ephp_web/deps/ephp/src/ephp.erl", line: 182]}, {EphpWeb.EphpPlug, :call, 2, [file: ~c"lib/ephp_web/ephp_plug.ex", line: 34]}, {Bandit.Pipeline, :call_plug, 2, [file: ~c"lib/bandit/pipeline.ex", line: 110]}, {Bandit.Pipeline, :run, 6, [file: ~c"lib/bandit/pipeline.ex", line: 25]}, {Bandit.HTTP1.Handler, :handle_data, 3, [file: ~c"lib/bandit/http1/handler.ex", line: 27]}]}}
Linked GitHub repository to easily reproduce the problem: https://github.com/osbre/ephp_web
git clone [email protected]:osbre/ephp_web.git && cd ephp_web
mix deps.get
mix run --no-halt
curl http://0.0.0.0:4000
5.15.0-75-generic
kernelIn ephp_lib_info.erl
there are specific parts needed of information, for example, in PHP the information about:
OS:
{unix, darwin}
as Darwin
{unix, linux}
as Linux
{win, nt}
as WINNT
{win, _}
as Windows
OS Family:
{unix, darwin}
as Darwin
{unix, linux}
as Linux
{win, nt}
as WINNT
{win, _}
as Windows
OS EOL: this part is forced to only \n
.
It should be configured properly.
The special use of list
function should be implemented in the parser and in the VM to match each parameter in the list with a value returned.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.