smuuf / primi Goto Github PK
View Code? Open in Web Editor NEWPrimi language: A scripting language written in PHP.
License: MIT License
Primi language: A scripting language written in PHP.
License: MIT License
i have tried to run the test for nomorearray branch but i got errors because the modules not loaded
https://github.com/smuuf/primi/tree/nomorearray
Run chmod +x ./primi ./bin/* && ./bin/test --php phpdbg --coverage xml
███ Smoke tests
Running: /example/comparisons.primi ...
Running: /example/dict.primi ...
Running: /example/errors_invoking_nonfunctions.primi ...
Running: /example/errors_wrong_inserting.primi ...
Running: /example/ext.bool.primi ...
Running: /example/ext.dict.primi ...
Running: /example/ext.list.primi ...
Running: /example/ext.number.primi ...
Smuuf\Primi\Ex\ErrorException: Undefined variable 'cos' @ <main: file /home/runner/work/primi/primi/example/ext.number.primi> on line 38, position 5
Traceback:
[0] <main: file /home/runner/work/primi/primi/example/ext.number.primi>
how we can load the modules
i have tried without any success
Currently import std.types
will always import module types
into variable types
, or import std.term.colors: Fg
will always import name Fg
from module std.term.colors
into variable Fg
.
What we want to allow are these:
>>> import std.types as lol_std_types
... or:
>>> import import std.term.colors: Fg as colors_fg
... or even:
>>> import import std.term.colors: Fg as colors_fg, Bg as colors_bg
Hi - it would be good if the if() built-in function had the ability to include else-if
clauses.
I hope you might consider.
Kind regards
Rick
>>> x[[1,2]]
PHP ERROR Smuuf\Primi\Ex\UnhashableTypeException: Unhashable type 'list' @ ./src/Values/AbstractValue.php:303
>>> dict("ahoj")
PHP ERROR ErrorException: Undefined offset: 1 @ ./src/Structures/MapContainer.php:68
...
The same error can be spawned with:
>>> dict([[1]])
PHP ERROR ErrorException: Undefined offset: 1 @ ./src/Structures/MapContainer.php:68
And with:
>>> dict([[]])
PHP ERROR ErrorException: Undefined offset: 0 @ ./src/Structures/MapContainer.php:68
I tried using Primi, however, could not get it to run the example. If I try to use the latest release (v0.4), it seems to not support php 8.2. If I try to use the dev version, the example in readme, does not work, as there appears to be a change in the construction of Context and Interpreter...
List syntax:
x = ['1', 1, 'b', ['x', 'y'], {'key_a': 'value_a', 'key_b': 'value_b'}]
Dict syntax:
x = {'key_a': 'value_a', 'key_b': 'value_b', 2: ['x', 'y', 10]}
Hello! Interesting development!
My question, is it possible to translate regular PHP multidimensional array into a multidimensional array ArrayValue of ArrayValue of Values.
For example:
$arrayValuesOfArrayValues = new ArrayValue(
[
['title' => 'hello'],
['title' => 'world']
]
)
UPD
Or maybe I have json array from user, and I want pass this array to Primi. How can I do it?
>>> c = 1
1
>>> c()
PHP Fatal error: Uncaught Error: Call to undefined method Smuuf\Primi\Structures\NumberValue::call()
Scope of a method should have access to "global" variables from the current module where the class was defined. At the same time method scope should NOT have direct access to attributes of the class (these should be accessible only via self
- and that's how it already is).
>>> oh_noes = 123
123 (number bac34a9a)
>>> class Something {
... function some_fn(self) {
... print(oh_noes)
... }
... }
>>> s = Something()
<instance 'Something' e0908f3a> (Something e0908f3a)
>>> s.some_fn()
Error: Undefined variable 'oh_noes' @ <module: __main__> on line 3
Traceback:
[0] <repl: cli> in <module: __main__>
[1] some_fn() in <module: __main__> called from <module: __main__> on line 1
Otherwise this also wouldn't work:
>>> import std.math
>>> class Something {
... function some_fn(self) {
... math.round(123.456)
... }
... }
... because math
is imported into module's global variables.
Example:
Variable 'a' is a string.
<?php
require __DIR__ . "/vendor/autoload.php";
$context = new \Smuuf\Primi\Context;
$interpreter = new \Smuuf\Primi\Interpreter($context);
$context->setVariable('teste', \Smuuf\Primi\Structures\Value::buildAutomatic(function() {
return 0.00000001;
}));
try {
$interpreter->run('a = teste()'); // expect variable 'a' be a Number but it is a string
foreach ($context->getVariables() as $name => $value) {
printf("%s (%s) ... %s\n", $name, $value::TYPE, json_encode($value->getInternalValue()));
}
} catch (\Smuuf\Primi\ErrorException $e) {
die($e->getMessage());
}
Hi, I just stumbled across this project, and this looks very interesting.
I was playing around with it a bit and noticed that there is no maximum recursion depth.
When calling a recursive function with no stop condition, it just loops forever:
function recursive(a) { recursive(a); }
It could be a good idea to set a hard limit like PHP, especially since this language targets clients.
This is a bug.
Primi gives:
>>> 5 ** 4 ** 2 ** 1
390625 (number 1d88feda)
But PHP gives:
$ php -r "print(5 ** 4 ** 2 ** 1);"
152587890625
And also Python gives:
$ python3 -c "print(5 ** 4 ** 2 ** 1)"
152587890625
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.