keosariel / gabby-lang

A simple programming language using llvmlite in python3
43 stars 9 forks source link

I wish you can continue the project #1

Open streetartist opened 3 years ago

Andrea-Miele commented 3 years ago

Yeah please this is the only good example of using llvmlite with a python lexer/parser , if you want to continue this project i Will be really supportive

streetartist commented 3 years ago

Can you give a example about "import a Module" and use c++ in llvmlite

keosariel commented 3 years ago

Yeah please this is the only good example of using llvmlite with a python lexer/parser , if you want to continue this project i Will be really supportive

I think I'd start the project over from scratch cuz it's a little bit old and I have much more exprience now, you giving me such feedback means alot to me.

So @Andrea-Miele what do you think? Besides sorry for the late reply

keosariel commented 3 years ago

Can you give a example about "import a Module" and use c++ in llvmlite

You'd need to convert whatever c++ code to llvm code that way you can easily use it across your code just like:(https://github.com/dabeaz/bitey). This would be the mechanism that I'd use to build most libraries in this project

Andrea-Miele commented 3 years ago

So @Andrea-Miele what do you think?

@keosariel way to create extensions/modules would be really cool , I also suggest you (if it's possible, I don't know if llvm IR has it) to implement Object Oriented Programming concepts

streetartist commented 3 years ago

I hope to implement import statements (similar to python), import modules that have been written (compiled with llvmlite), and even import c libraries. This will make a basically usable programming language.

streetartist commented 3 years ago

"implement Object Oriented Programming concepts"

I wish as well.

Andrea-Miele commented 3 years ago

May I ask you something, where did you learn how use llvmlite? I cannot found any good documentation or good example (except for this repo but I cannot understand it a lot)

streetartist commented 3 years ago

I cannot find good documentation anywhere too. I learn it by reading the code of the project gone.

Andrea-Miele commented 3 years ago

I learn it by reading the code of the project gone.

Oh ok

streetartist commented 3 years ago

https://github.com/Lesma-lang/Lesma https://github.com/paivett/gone https://github.com/syegulalp/Akilang

There are some projects.

I think We can improve the example together.

streetartist commented 3 years ago

I think the Int in the project should all Change to the type_map.

Why using previous_builder in the function visit_def?

streetartist commented 3 years ago

I found a way to link c in llvmlite.

https://stackoverflow.com/questions/36658726/link-c-in-llvmlite

Andrea-Miele commented 3 years ago

@streetartist yeah i also found that

Andrea-Miele commented 3 years ago

I searched in the llvmlite documentation and I didn't find any reference to Object Oriented Programming concepts

Andrea-Miele commented 3 years ago

i realized that to make classes we can simply make stuctures and then make some methods with the first argument of the instance itself

Andrea-Miele commented 3 years ago

i made this test

import llvmlite.ir as ir
import llvmlite.binding as llvm
import ctypes
module = ir.Module("OOP")

#Let's make a class called Foo, dividing it in a structure and some methods
Foo = module.context.get_identified_type("Foo")
Foo.set_body(
    ir.IntType(32)
)
constructor = ir.Function(module,ir.FunctionType(ir.VoidType(), [Foo.as_pointer()]),"Foo_Create_Default")
constructor.attributes.add("nounwind")
constructor.args[0].name="this"
block = constructor.append_basic_block("entry")
builder = ir.IRBuilder(block)
my_ptr = constructor.args[0]

ptr = builder.gep(my_ptr,[ir.Constant(ir.IntType(32),0),ir.Constant(ir.IntType(32),0)], name="1")
builder.store(ir.Constant(ir.IntType(32),0), ptr)
builder.ret_void()

main_typ = ir.FunctionType(ir.IntType(32), [])
main_func = ir.Function(module,main_typ,"main")
main_block = main_func.append_basic_block("entry")
main_builder = ir.IRBuilder(main_block)
foo = main_builder.alloca(Foo,name='foo')
main_builder.call(constructor, [foo])
new_ptr = main_builder.gep(foo, [ir.Constant(ir.IntType(32),0),ir.Constant(ir.IntType(32),0)])
main_builder.store(ir.Constant(ir.IntType(32),20),new_ptr)
myval = main_builder.load(new_ptr)
main_builder.ret(myval)
print(module)

llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter() 
target = llvm.Target.from_default_triple()
target_machine = target.create_target_machine()
backing_mod = llvm.parse_assembly("")
engine = llvm.create_mcjit_compiler(backing_mod, target_machine)
mod = llvm.parse_assembly(str(module))
mod.verify()
engine.add_module(mod)
engine.finalize_object()
ptr = engine.get_function_address("main")
ctype = ctypes.CFUNCTYPE(ctypes.c_int32)(ptr)
print(ctype())
Andrea-Miele commented 3 years ago

wait @streetartist you already implemented classes in your language

streetartist commented 3 years ago

I think we can have a look at the project Lesma,it has already implemented OOP

keosariel commented 3 years ago

So @Andrea-Miele what do you think?

@keosariel way to create extensions/modules would be really cool , I also suggest you (if it's possible, I don't know if llvm IR has it) to implement Object Oriented Programming concepts

OOP isn't implemented in LLVM, though I've found a way around it.

keosariel commented 3 years ago

I cannot find good documentation anywhere too. I learn it by reading the code of the project gone.

May I ask you something, where did you learn how use llvmlite? I cannot found any good documentation or good example (except for this repo but I cannot understand it a lot)

I just read and tweeked some code I found on github, besides the code wasn't documented at all. However, the llvmlite module has comments in it's code so I just walked my way backwards.

keosariel commented 3 years ago

I broke the Akilang https://github.com/syegulalp/Akilang project to pieces too, to learn to use llvmlite

keosariel commented 3 years ago

I think we can have a look at the project Lesma,it has already implemented OOP

The way Lesma implemented OOP is nice and I used the same technique they used. I've actually implemented OOP for this project but I didn't just upload the code cuz I've not really commented/documented the code yet.

keosariel commented 3 years ago

Besides we'd need a todo list

i made this test

import llvmlite.ir as ir
import llvmlite.binding as llvm
import ctypes
module = ir.Module("OOP")

#Let's make a class called Foo, dividing it in a structure and some methods
Foo = module.context.get_identified_type("Foo")
Foo.set_body(
    ir.IntType(32)
)
constructor = ir.Function(module,ir.FunctionType(ir.VoidType(), [Foo.as_pointer()]),"Foo_Create_Default")
constructor.attributes.add("nounwind")
constructor.args[0].name="this"
block = constructor.append_basic_block("entry")
builder = ir.IRBuilder(block)
my_ptr = constructor.args[0]

ptr = builder.gep(my_ptr,[ir.Constant(ir.IntType(32),0),ir.Constant(ir.IntType(32),0)], name="1")
builder.store(ir.Constant(ir.IntType(32),0), ptr)
builder.ret_void()

main_typ = ir.FunctionType(ir.IntType(32), [])
main_func = ir.Function(module,main_typ,"main")
main_block = main_func.append_basic_block("entry")
main_builder = ir.IRBuilder(main_block)
foo = main_builder.alloca(Foo,name='foo')
main_builder.call(constructor, [foo])
new_ptr = main_builder.gep(foo, [ir.Constant(ir.IntType(32),0),ir.Constant(ir.IntType(32),0)])
main_builder.store(ir.Constant(ir.IntType(32),20),new_ptr)
myval = main_builder.load(new_ptr)
main_builder.ret(myval)
print(module)

llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter() 
target = llvm.Target.from_default_triple()
target_machine = target.create_target_machine()
backing_mod = llvm.parse_assembly("")
engine = llvm.create_mcjit_compiler(backing_mod, target_machine)
mod = llvm.parse_assembly(str(module))
mod.verify()
engine.add_module(mod)
engine.finalize_object()
ptr = engine.get_function_address("main")
ctype = ctypes.CFUNCTYPE(ctypes.c_int32)(ptr)
print(ctype())

Sweet

keosariel commented 3 years ago

I think I'd create a new Repo and invite you guys, then we'd need to layout the workflow and also create a todo list sort of, just so we are guided and at the same time we get to know what left and whats not while writing the code.

Greate??

keosariel commented 3 years ago

However, I know we all love Python and I don't think we'd stop writing python anytime soon. So I'm thinking we should write a flavour of RPython. Buh instead of converting statically typed Python code to C/C++ we'd convert it to LLVM IR and we'd need to also devise a means to use the language in Python.

What do you guys think?

Andrea-Miele commented 3 years ago

I think I'd create a new Repo and invite you guys, then we'd need to layout the workflow and also create a todo list sort of, just so we are guided and at the same time we get to know what left and whats not while writing the code.

Yeah, we'll do that

Andrea-Miele commented 3 years ago

However, I know we all love Python and I don't think we'd stop writing python anytime soon. So I'm thinking we should write a flavour of RPython. Buh instead of converting statically typed Python code to C/C++ we'd convert it to LLVM IR and we'd need to also devise a means to use the language in Python.

@keosariel it already exists, it's called Numba, it's a python jit based on llvmlite that can also emit llvm IR code

streetartist commented 3 years ago

Great

Andrea-Miele commented 3 years ago

Also I think we'll need a better way to communicate

streetartist commented 3 years ago

What way

Andrea-Miele commented 3 years ago

What way

I don't know

streetartist commented 3 years ago

And we must write a standard libarary for it(using llvm or C++), and the program must can import from other program written in this language.

Andrea-Miele commented 3 years ago

and the program must can import from other program written in this language.

Yeah, we have to make this

streetartist commented 3 years ago

https://github.com/Lesma-lang/Lesma/issues/3

Andrea-Miele commented 3 years ago

And we must write a standard libarary for it(using llvm or C++),

I don't know C++, for me it will be better to make it in llvm

keosariel commented 3 years ago

However, I know we all love Python and I don't think we'd stop writing python anytime soon. So I'm thinking we should write a flavour of RPython. Buh instead of converting statically typed Python code to C/C++ we'd convert it to LLVM IR and we'd need to also devise a means to use the language in Python.

@keosariel it already exists, it's called Numba, it's a python jit based on llvmlite that can also emit llvm IR code

I know of numba, but I'm talking of a pair just the way c is to c++ sort off

keosariel commented 3 years ago

and the program must can import from other program written in this language.

Yeah, we have to make this

Yeah sure

keosariel commented 3 years ago

Lesma-lang/Lesma#3

Mad stuff :smile: :smile:

keosariel commented 3 years ago

Also I think we'll need a better way to communicate

Let's communicate on discord. Would that favour you guys??

streetartist commented 3 years ago

can you update your code for oop? I want to have a look

Andrea-Miele commented 3 years ago

Let's communicate on discord. Would that favour you guys??

Yes ,for me it's good

Andrea-Miele commented 3 years ago

can you update your code for oop? I want to have a look

Yeah please do that

keosariel commented 3 years ago

can you update your code for oop? I want to have a look

Yeah please do that

I'd do that as soon as possible

keosariel commented 3 years ago

However, I've just created a new repo and invited you guys already. Please don't mind the repo's name (:hint github suggested it) :smile: :smile:

I've also sent @Andrea-Miele discord friend request @streetartist pls your discord tag

keosariel commented 3 years ago

can you update your code for oop? I want to have a look

Yeah please do that

I'd do that as soon as possible

Yo guys, the code is so soo messy!!! Most of the stuff I did in the code was just proof of concept for a new language I was going to build, which I ended up not building

Andrea-Miele commented 3 years ago

@keosariel we cannot talk on discord Your account is hacked Never click links that promise nitro

keosariel commented 2 years ago

Sorry I've been having issues with my e-mail, which affected my Github. I still don't understand why my discord was suspended. However, I've written some code for starters and I'd upload it tomorrow. Besides we'd need to talk on how the syntax would work.

Sorry!!!!

keosariel commented 2 years ago

Any recommendation on a communication platform??

Andrea-Miele commented 2 years ago

I still don't understand why my discord was suspended.

Probably because you got hacked Screenshot_20211106-150623_Discord.jpg

Any recommendation on a communication platform??

I don't know. I used to use discord, but if your account is suspended we need to find an alternative