marcobambini / gravity Goto Github PK
View Code? Open in Web Editor NEWGravity Programming Language
Home Page: https://gravity-lang.org
License: MIT License
Gravity Programming Language
Home Page: https://gravity-lang.org
License: MIT License
There seems to be no contribution guide for people that would love to help with your project.
Gravity to C/Golang source code transcompiler
just like https://github.com/google/grumpy
Hi, when I've called unknown function on System
object I've got segmentation fault.
Reproduce:
test.gravity
func main() {
System.unknown_function();
}
run:
./gravity test.gravity
[1] 24208 segmentation fault (core dumped) ./gravity test.gravity
Also which extension of gravity files I should use? .gravity
/.gr
or something else?
When compiling Gravity there are some warnings that really annoy me.
Anyone know how to get rid of them?
For example:
warning: redefinition of typedef
'gravity_class_t' is a C11 feature [-Wtypedef-redefinition]
} gravity_class_t;
Hello, I think it is a good idea to make a group chat for people to discuss about Gravity. For example Slack chat would let this small community grow faster.
Consider the testcase that tests adding values to a list:
#unittest {
name: "Test Adding Values to a List";
error: NONE;
result: "[0, 1, 2, 3, 4]";
};
func main() {
var x = [];
x[0] = 0;
x[1] = 1;
x[2] = 2;
x[3] = 3;
x[4] = 4;
System.print("x[0] = " + x[0]);
System.print("x[1] = " + x[1]);
System.print("x[2] = " + x[2]);
System.print("x[3] = " + x[3]);
System.print("x[4] = " + x[4]);
var ret = "[" + x[0] + ", "
+ x[1] + ", "
+ x[2] + ", "
+ x[3] + ", "
+ x[4] + "]";
return ret;
}
With the following run output:
==============================================
Gravity UnitTest
Gravity version 0.2.5
Build date: Mar 6 2017
==============================================
1 Test file: list_add_values.gravity
Test path: ./mine/list_add_values.gravity
Test Adding Values to a List
x[0] = null
x[1] = 1
x[2] = null
x[3] = 3
RUNTIME ERROR: Out of bounds error: index 4 beyond bounds 0...3
FAILURE
==============================================
Total Tests: 1
Total Successes: 0
Total Failures: 1
Result: 0.00 %
Time: 0.6083 ms
==============================================
As you can see, it seems as though index 0, 2, and 4 are never set, causing an out of bounds error while trying to get the value at index 4.
Hey there,
I'm playing with gravity for a while now and I really like it :)
But what I wonder is if the return value of the main()
function shouldn't be the return value of the program, so if I write return 5;
I assume the program to exit with error code 5. Maybe It's my fault or it's a design decision.
Nice project, have a good time
Please add async and await into your Reserved Keywords. I have not seen support of async programming in gravity now, but it will be useful once you will want to add it.
BTW I'm glad that you are not trying to invent wheel and that you use standard, well known syntax from the C** world. Looks nice
This code
func main() {
var boolean = true;
boolean &= false;
return boolean;
}
Causes a runtime error.
RUNTIME ERROR: Unable to perform operator BAND on object
Similarly with other languages where you want to keep things organized by having different functionality implemented in different files, is there a way to have multiple gravity files with different functionality, and combine them?
As an example, say one gravity file is a function that calculates the factorial of a number, and the other file contains the main function where you will call the factorial function from the other file.
Is such a thing possible?
This is a common solution for fields that are shadowed by a paremter. This may be personal preference, but I think that this
func init(x, y) {
this.x = x;
this.y = y;
}
looks more clean than this
func init(x, y) {
_x = x;
_y = y;
}
Sometimes is necessary to dynamic call a function by passing its arguments as a list. In javascript, we have Function.apply method for this.
I didn't find a native way to implement this, so I reverted to do this weird trick in gravity-func:
func apply (fn, args) {
if (args.count == 1) return fn(args[0]);
if (args.count == 2) return fn(args[0], args[1]);
if (args.count == 3) return fn(args[0], args[1], args[2]);
if (args.count == 4) return fn(args[0], args[1], args[2], args[3]);
if (args.count == 5) return fn(args[0], args[1], args[2], args[3], args[4]);
if (args.count == 6) return fn(args[0], args[1], args[2], args[3], args[4], args[5]);
}
I think a native method that allow for any number of arguments could be useful to have.
Hello community. I have a suggestion - Pipe operator. It would be a syntactic sugar for nested functions. Pipe operator is widely used in functional programming (for example Elm
, Elixir
, F#
, Haskell
) and it gives code really clean look and makes everything way more readable.
Imagine this:
String.split(String.capitalize(String.reverse("Gravity is awesome!")));
with pipe operator it would look like
"Gravity is awesome!"
|> String.reverse()
|> String.capitalize()
|> String.split()
which I think is way better! What do you think? Comment and maybe suggest your ideas.
Here I have another suggestion, this time about our Gravity's CLI. I come up with this list of improvements which I think should benefit the project:
REPL
REPL
add a new flag for example gravity --repl
gravity new [project]
- a new simple command to create new project. (A wizard which helps with common things would be even better! Just like NPM's wizard.)--bytecode
which would output generated bytecode instead of running the application.I would love to have these things actually implemented and would like to discuss it with others π
I'm having a build error with MinGW on Windows 10 trying to build the github after cloning
The full error log is available in a pastebin here
The log seems to indicate inline functions being declared never being properly defined
I had a couple issues while compiling Gravity on Ubuntu. Here's what I did to make it compile:
#include <stdint.h>
to the top of debug_macros.hLDFLAGS = -lm
in the Makefile for some math functions such as ceil and pow.Hope this helps.
just curious, you mentioned its similar. Since swift is open source.. couldn't you utilize it however you'd like?
guess i'm always curious when a new language comes out as to the pros and cons of yet another language on the market with some slight differences to all the others out there.
I wanted to try fiddling around with the embedding api allthough i think the
VALUE_FROM_CLOSURE
macro mentioned in the api docs seems to be missing from the source. Can you help me out?
Given this code
func half (n) {
return n / 2;
}
func main () {
System.print(half is Function);
System.print(half is Object);
}
I will expect an output of
true
true
But what I get is
false
true
So, half is Function
return false. How can I check if something is a function?
I hope I haven't missed this but I didn't see anything about class extension in the documentation, are there any plans for this or is it already supported in any way?
I have an interest in using Gravity for game scripting and class extension would be very useful.
Not sure about your current naming conventions yet, but can we have class names be starting with uppercase letter and functions/methods with lowercase?
return obj0.sum() + obj1.sum() + obj2.sum() + obj3.sum() + obj4.sum2() + c4.sum1();
is vastly more readable than:
return obj0.Sum() + obj1.Sum() + obj2.Sum() + obj3.Sum() + obj4.Sum2() + c4.Sum1();
I've always wanted to create one and Gravity looks like an amazing language - would a creation such as npm/yarn be up for grabs?
From the README.md example:
return "[" + x.String() + "," + y.String() + "," + z.String() + "]";
Both JavaScript and Ruby (and probably others) have a syntax similar to the following:
return `[${x.String()}, ${y.String()}, ${z.String()}]`;
(note interpolation-ready strings use backticks not quotes)
This'd be a really neat feature to have in Gravity.
In For loop pushing new element on current list cause infinite loop
func main() {
var numbers = [1,2,3,4,5,6,7,8,9];
for (var number in numbers) {
numbers.push(10);
System.print("Current number is " + number);
}
}
Awesome Work π π π !!!!
As many would will have or i have this question how these programming language are crafted. As Gravity been developed it would be great if you could share some of you experience by given a talk on ......
Sorry for my long post π
Hi!
I am having some issues compiling the parser. Before I start, I should mention I am using an IBM i C compiler - you can read more about its standards here, although I believe it is up to C99. This environment does not have make, so I am having to manually compile all the modules in order to create the ending object/program.
When I try compile gravity_parser.c
, I am getting 5 compile errors when I which all relate to the same thing:
CZM0117: Operand must be a scalar type.
Cause . . . . . : Valid scalar types include: signed and unsigned char;
signed and unsigned short, long, long long, and int; enum, float, double,
long double, and pointers.
Recovery . . . : Change the type of the operand, or use a different
operator.
All errors are pointing to (gtoken_s)NO_TOKEN
Line 1164: enum_value = (gnode_base_t *)gnode_literal_int_expr_create((gtoken_s)NO_TOKEN, enum_autoint);
Line 1365: gnode_t *outer_var = gnode_variable_create((gtoken_s)NO_TOKEN, string_dup(OUTER_IVAR_NAME), NULL, 0, NULL);
Line 1368: gnode_t *outer_decl = gnode_variable_decl_create((gtoken_s)NO_TOKEN, TOK_KEY_VAR, TOK_KEY_PRIVATE, 0, decls);
Line 2070: gnode_t *node= gnode_block_stat_create(NODE_LIST_STAT, (gtoken_s)NO_TOKEN, parser->statements);
Line 2138: return gnode_block_stat_create(NODE_LIST_STAT, (gtoken_s)NO_TOKEN, parser->statements);
The error is surely related to this systems compiler. I am not a C pro, so I was wondering if anyone could give me some pointers to what I should do to fix this.
Thanks,
Liam
something isa Int
doesn't flow as well as something is Int
gravity_lexer_free
frees the string buffer internally
if ((!lexer->is_static) && (lexer->buffer)) mem_free(lexer->buffer);
yet when the lexer is created, the buffer member is not copied but set to the one supplied
lexer->buffer = source;
which as a side effect prematurely frees the source code string buffer
https://github.com/marcobambini/gravity/blob/master/src/cli/gravity.c#L179
After gravity_compiler_run
is being called there, source_code
becomes undefined which becomes a problem, and in fact crashes in my C# bindings.
https://github.com/marcobambini/gravity/blob/master/docs/maps.html#L115
var people = ["Mark":1, "Andrew":2, "Paul":3, "Ross":4];
map["Kiara"] = 5; // map now contains the "Kiara" key with value 5
should be people
not map
.
I would expect a runtime error when I try to call undefined
or null
values, but instead I get a null
value and no error.
func main() {
// "ciao"(); // RUNTIME ERROR: Unable to call object (in function main)
// 42(); // RUNTIME ERROR: Unable to call object (in function main)
// 42.42(); // RUNTIME ERROR: Unable to call object (in function main)
null(); // no error thrown
undefined(); // no error thrown
}
I'm using Gravity version 0.2.5 (Mar 9 2017) on OSX 10.10.5
I'm in love with gravity .. I can feel the chemistry between us.
Gravity built-ins are currently hardcoded into the compiler. I believe it would be better to port the non-primitives to Gravity so that people can still contribute to Gravity's core without being familiar with the internal details of the compiler.
These are some examples of data structures that could easily be implemented:
Does the System class have methods for reading from stdin?
I can see no mention of it here: https://marcobambini.github.io/gravity/system.html
Besides some way to load other modules written in gravity, i would suggest implementing the functionality to load native libraries as modules too.
For example module "test"
would load test.gravity
but in case that does not exist it would try test.dll
or test.so
and load a global gravity_load
function where you can register functions/classes using the native API.
Today I wrote some example, just to start learning the language.
In the hope it could be helpful to others as learning material, here is it: https://github.com/parro-it/gravity-func
By now, I implemented a map
and a filter
functions, I'll also try to add following ones:
Feel free to suggests other function you think may fit...
Do you plan to rewrite Gravity compiler in Gravity one day?
I'm not sure this is an error or a design choice but the code below returns (INT) 10
. Shouldn't it not compile because we're trying to sum different types?
class Point {
var _x;
var _y;
func init(x, y) {
_x = x;
_y = y;
}
func String() {
return _x + "x" + _y;
}
}
func main() {
var point = Point(5, 5);
return point.String();
}
Forgive me if this is a a feature of the language, I just started testing some code.
I have tried some simple code with the import, and it did not work, so I went to write a testcase, but the testcase actually works and passes...
Consider the testcase:
import "../test.gravity"
#unittest {
name: "Test Adding Values to a List";
error: NONE;
result: "testtesttest";
};
func main() {
return test();
}
and then consider this regular file:
import "../test.gravity"
func main() {
return test();
}
where the contents of ../test.gravity are:
func test() {
return "testtesttest";
}
Running the testcase yields this result:
$ gravity-unittest .
==============================================
Gravity UnitTest
Gravity version 0.2.5
Build date: Mar 7 2017
==============================================
1 Test file: mytest.gravity
Test path: ./mytest.gravity
Test Import
SUCCESS
==============================================
Total Tests: 1
Total Successes: 1
Total Failures: 0
Result: 100.00 %
Time: 0.4988 ms
==============================================
But just running the regular file:
$ gravity mytest.gravity
SYNTAX ERROR on 0 (1,8): Unable to load file because no loadfile callback registered in delegate.
gravity: src/cli/gravity.c:160: main: Assertion `closure' failed.
Aborted (core dumped)
Is anyone interested in extension for Visual Studio Code for syntax highlighting? I have simple extension already working, with minor modifications I could add it on Github if anyone is interested.
this project is very good china people need it οΌοΌThere is a market in China οΌkeep it light optimization speed
To add usability, the "Getting Started" instructions in the Gravity Docs.
git clone https://github.com/marcobambini/gravity.git
cd gravity
make
mv gravity /usr/local/bin
support docker like other lang (go pony rust ) !! give a official image !! this is a good way Development environment is the same Thx !
Could you provide some feedback regarding the advantages of Gravity over Lua-based experiments like e.g. https://github.com/richardhundt/shine or https://github.com/leafo/moonscript?
Those project translate an extended syntax (e.g. supporting classes, try/catch, etc) into a standard Lua source code or onto Lua/LuaJIT bytecode. And providing a new syntax on top of Lua is extremely easy (see Shine as an example). They do not require any changes of the Lua VM. And they can be used with LuaJIT, which gives a huge performance boost.
It would be interesting to understand why Gravity goes for its own VM and what advantages this VM provides over Lua VM/LuaJIT or Wren VM.
// file scope can refer to a name
// before it has been fully declared
func f1() {
return f2();
}
func f3() {
return 42;
}
// block scope can be nested and
// can hide other local variables
func f3() {
var a = 10;
if (a > 0) {
var a = 20;
}
// 10 is returned here
return a;
}
I believe there is a typo here: func3 is declared twice, but func2 is not declared.
I didn't find anything in the documentation.
I just saw your repo and the first things that caught my attention were concurrent and scripting language. And the query is: Are threads implemented?? Are they OS native or VM native?? And how is thread safety implemented?? And the ever popular: Is there andy kind of Global Interpreter Lock??
Hey
Congrats on releasing a new language.
I wanted to ask you, why a Ruby-like syntax which in my opinion is more lovely, never makes the cut. I often pray sheepishly if ever a new language comes out, if it could be readable like Ruby.
Imagine my pique when developers like you address such practical scenario so elegantly, end up with curly braces.
Why-oh-why?
Being able to reload the code at runtime would allow for fast iteration cycles of gravity code. Upon loading a gravity script, existing classes would be replaced with the changed classes, while keeping the state of existing objects .
The following program is expected to output Hello 1 2 3
func main() {
System.print("Hello");
var nums = [1, 2, 3];
for (var num in nums) {
System.print(num);
}
}
However, the actual output is Hello null 1 2
Seems the first System.print affects the System.print in the for loop.
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.