Skip to content

Add B++ to README#187

Merged
dannypsnl merged 1 commit intollir:masterfrom
Nv7-GitHub:master
Jun 11, 2021
Merged

Add B++ to README#187
dannypsnl merged 1 commit intollir:masterfrom
Nv7-GitHub:master

Conversation

@Nv7-GitHub
Copy link
Copy Markdown
Contributor

Adds B++ to the README

@dannypsnl dannypsnl merged commit 3ab8f5a into llir:master Jun 11, 2021
@mewmew
Copy link
Copy Markdown
Member

mewmew commented Jun 11, 2021

Thanks for sharing @Nv7-GitHub! Really cool to see what you've been working on :)

Lovely to see you've developed both a compiler (B++ -> LLVM IR), an interpreter and a transpiler (B++ -> Go)!

While you have it fresh in mind, it would be great if you shared some of your experience with using llir/llvm when developing Bpp. What went smooth? Where did you run into problems or what parts of the API were confusing or difficult to work with?

I had a quick look at the source code and from first glance it looks quite clean and well structured. In compile/builtin.go I noticed a pattern which may be quite common for constructing NULL-terminated string constants, e.g. "foo" + string(rune(0)).

	openBracket = m.NewGlobalDef("openbracket", constant.NewCharArrayFromString("["+string(rune(0))))
	closeBracket = m.NewGlobalDef("closebracket", constant.NewCharArrayFromString("]"+string(rune(0))))

Since this pattern will be common also for other users of llir/llvm I think it would be worth creating a utility function for it, and most likely place it in llir/irutil.

For instance:

package irutil

// NewCString returns a new NULL-terminated character array constant based on the given UTF-8 string contents.
func NewCString(s string) *constant.CharArray {
   return constant.NewCharArrayFromString(s + "\x00")
}

Then builtin.go would be updated to:

-	openBracket = m.NewGlobalDef("openbracket", constant.NewCharArrayFromString("["+string(rune(0))))
-	closeBracket = m.NewGlobalDef("closebracket", constant.NewCharArrayFromString("]"+string(rune(0))))
+	openBracket = m.NewGlobalDef("openbracket", irutil.NewCString("[")
+	closeBracket = m.NewGlobalDef("closebracket", irutil.NewCString("]")

Or something along those lines.

So, it would be interesting to hear more about your experience. Especially what parts were a bit frustrating and confusion with using llir/llvm so we can make it easier for users, improve the API, and add missing documentation where needed.

Cheers,
Robin

Edit: irutil.NewCString has now been added (ref llir/irutil@039aa7b)

@Nv7-GitHub
Copy link
Copy Markdown
Contributor Author

Thank You!

I switched all my strings over to irutil.NewCString! I like this project a lot, its way easier to use than the C LLVM API. It made generating LLVM code super easy and fun, and I'm so glad I chose it over the C LLVM API!

I would say the biggest difficulty was the C standard library - it would be super cool to have a stdlib package, with bindings to the standard library. In the compiler/builtins.go file I wrote out the function signatures for a bit of the stdlib, but it would be awesome to automatically have bindings to the whole C stdlib.

I love this library and it makes generating LLVM a breeze!

@mewmew
Copy link
Copy Markdown
Member

mewmew commented Jun 13, 2021

I would say the biggest difficulty was the C standard library - it would be super cool to have a stdlib package, with bindings to the standard library. In the compiler/builtins.go file I wrote out the function signatures for a bit of the stdlib, but it would be awesome to automatically have bindings to the whole C stdlib.

That's a good idea! I know this has come up in the past, so adding something like irutil/stdlib would be good. I'll create an issue for it.

Happy you enjoyed hacking on a compiler using llir/llvm :) Should you wish in the future, you are always welcome to join us in planning and discussing for new features of llir/llvm.

With kindness,
Robin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants