Open streetartist opened 3 years ago
Can you give a example about "import a Module" and use c++ in llvmlite
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
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
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
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.
"implement Object Oriented Programming concepts"
I wish as well.
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 cannot find good documentation anywhere too. I learn it by reading the code of the project gone.
I learn it by reading the code of the project gone.
Oh ok
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.
I think the Int in the project should all Change to the type_map.
Why using previous_builder in the function visit_def?
https://stackoverflow.com/questions/36658726/link-c-in-llvmlite
@streetartist yeah i also found that
I searched in the llvmlite documentation and I didn't find any reference to Object Oriented Programming concepts
i realized that to make classes we can simply make stuctures and then make some methods with the first argument of the instance itself
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())
wait @streetartist you already implemented classes in your language
I think we can have a look at the project Lesma,it has already implemented OOP
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.
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.
I broke the Akilang https://github.com/syegulalp/Akilang project to pieces too, to learn to use llvmlite
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.
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
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??
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?
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
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
Great
Also I think we'll need a better way to communicate
What way
What way
I don't know
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.
and the program must can import from other program written in this language.
Yeah, we have to make this
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
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
and the program must can import from other program written in this language.
Yeah, we have to make this
Yeah sure
Mad stuff :smile: :smile:
Also I think we'll need a better way to communicate
Let's communicate on discord. Would that favour you guys??
can you update your code for oop? I want to have a look
Let's communicate on discord. Would that favour you guys??
Yes ,for me it's good
can you update your code for oop? I want to have a look
Yeah please do that
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
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
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
@keosariel we cannot talk on discord Your account is hacked Never click links that promise nitro
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!!!!
Any recommendation on a communication platform??
I still don't understand why my discord was suspended.
Probably because you got hacked
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
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