Giter Club home page Giter Club logo

gravity's People

Contributors

badcc avatar bendl avatar brandon-ray avatar bynect avatar drkameleon avatar fingolfin avatar foobit avatar hallzy avatar hkdnet avatar ibara avatar islc avatar kirantambe avatar leonardosnt avatar makenowjust avatar marcobambini avatar masrourmouad avatar matansilver avatar mbndr avatar neysofu avatar pamarcos avatar robloach avatar roemerb avatar rwhitworth avatar sargun avatar sbarisic avatar scottstensland avatar stevefan1999-personal avatar sunking2 avatar tdwtp avatar timgates42 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gravity's Issues

async and await

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

docker support

support docker like other lang (go pony rust ) !! give a official image !! this is a good way Development environment is the same Thx !

Build issue on Windows with MinGW

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

What advantages Gravity provides over "face-lifted" dialects of Lua with more modern syntax?

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.

Suggestion: Lets improve CLI

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:

  • If no arguments passed it should display help section instead of opening REPL
  • To open 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.)
  • Add a flag --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 πŸ˜ƒ

Unable to compile the gravity_parser.c

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

Segmentation fault on unknown function call

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?

Hot code reload

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 .

how to check type of functions?

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?

Error in blocks and scope doc

	// 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.

System.print incorrect output in Loop

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.

Will extending classes be supported?

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.

Suggestion: Add something like a this keyword to classes

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;
}

calling null or undefined does not throw a runtime error

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

Syntax

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?

Should Gravity's standard library be written in Gravity?

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:

  • hash tables,
  • binary trees,
  • sets and other collections.

Support bitwise operators on boolean

This code

func main() {
  var boolean = true;
  boolean &= false;

  return boolean;
}

Causes a runtime error.

RUNTIME ERROR: Unable to perform operator BAND on object

import doesn't seem to be working

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)

Module system suggestions

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.

Visual Studio Code syntax

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.

Suggestion: string interpolation

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.

Example repo

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:

  • curry
  • reduce
  • compose
  • pipe
  • reverseArgs

Feel free to suggests other function you think may fit...

gravity project needs a clear roadmap + other suggestions

I'm in love with gravity .. I can feel the chemistry between us.

  • Providing a clear roadmap would be awesome.
  • Improving the ecosystem by providing rich APIs < io, network , process , etc...>
  • Request for fundraising .. we can help to speed up the development process.

VALUE_FROM_CLOSURE macro missing

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?

ide or editor support

this project is very good china people need it !!There is a market in China ,keep it light optimization speed

naming conventions

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();

main() return value

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

Community chat

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.

Contributing

There seems to be no contribution guide for people that would love to help with your project.

Purpose: Closures `apply` method

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.

Question: How it is Done??

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 ......

  • How gravity works or how it all started ?
  • Implementing small feature ?
  • References or Guide or something like that you used during the development ?

Sorry for my long post 😁

Int + String + Int returns Int

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.

why not swift?

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.

Thread safety in Gravity???

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??

Bootstrapping

Do you plan to rewrite Gravity compiler in Gravity one day?

Suggestion: Pipes

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.

Possible issue with addings values to lists?

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.

Is there a way to use multiple gravity files?

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?

Getting rid of the warning: redefinition of typedef

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;

gravity_lexer_free frees the string buffer

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.

Issues compiling

I had a couple issues while compiling Gravity on Ubuntu. Here's what I did to make it compile:

  1. add #include <stdint.h> to the top of debug_macros.h
  2. set LDFLAGS = -lm in the Makefile for some math functions such as ceil and pow.

Hope this helps.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.