First release: https://github.com/Willyboar/glove
Probably the code is bad, because this is my first library in gleam. I will try to provide a basic example as soon as possible.
#Glove - A gleam library for creating QBE IR
1 messages · Page 1 of 1 (latest)
I used textcraft.net for the logo
this is a working example. Needs some polish but compiles: ```rs
import gleam/io
import gleam/option.{None, Some}
import glove
pub fn main() {
let data_def =
glove.DataDef(
linkage: glove.Linkage(exported: False, section: None, secflags: None),
name: "str",
align: None,
items: [
#(glove.Byte, glove.Str("hello world")),
#(glove.Byte, glove.Constant(0)),
],
)
let main_func =
glove.Function(
linkage: glove.public(),
name: "main",
arguments: [],
return_ty: Some(glove.Word),
blocks: [
glove.Block(
label: "@start",
statements: [
glove.Assign(
glove.Temporary("r"),
glove.Word,
glove.Call(
glove.Global("puts"),
[#(glove.Long, glove.Global("str"))],
),
),
glove.Volatile(glove.Ret(Some(glove.Const(0)))),
],
),
],
)
let empty_module = glove.Module(functions: [], types: [], data: [])
empty_module
|> glove.add_data(data_def)
|> glove.add_function(main_func)
|> glove.display_module
|> io.print
}
// Expectable result:
//export function w $main() {
//@start
// # Call the puts function with $str as argument.
// %r =w call $puts(l $str)
// ret 0
//}
//
//data $str = { b "hello world", b 0 }
Oh derp im dumb you answered the same question above 😂
This looks cool!
What’s QBE
🙃
It is a compiler backend
Oooooo
the library creates qbe ir code that compiles with the qbe to assembly
That’s so cool 😮
The code example i provided creates the QBE code to create a executable to say: hello world 😛
GLEAM NATIVE LIVES
I uploaded the example to a separate repo: https://github.com/Willyboar/glove_example
Once path deps are released you can put them in the same repo 😄
I am thinking if I have to add export file with the code or let users to do it.
I'd just let them do it
Next steps: 1. Cover more qbe instructions. 2. Write a small AST to QBE IR example.
@next hedge and @cunning sierra i hope you don't mind I added your names in special thanks section
I did nothing! 😄
Yeah that's fine with me! Thanks 😄
You create gleam! 😜
Makes language…
“Psh what is this garbage it barely counts”
@next hedge as dr frankenstein talking to his creation: “what the hell what kind of moron made you”
I will add @simple hawk too, if she use it for yak 😛
I just wish qbe had windows support
I did end up testing it on windows and it didn't work
Yeah me too
This is why I want to make another library.
qwindows
If qbe supported windows I wouldn't bother
maybe just like try to add support instead of starting from scratch then
I think he wanted to make a C generation library rather than a qbe alternative
Globe! Great name @finite compass
I believe they don't want windows support.
based
There was an answer on adding windows support to another user: "choose a better OS" 🤣🤣
id say the same thing tbh but I wouldnt complain if someone implements it for me
Well I am not a windows user so I don't want to spend time to implement it.
Also programming is a hobby for me so I prefer to contribute something to gleam community.
@finite compass Sorry for the long link but https://lists.sr.ht/~mpu/qbe/<20230126110943.14927-1-t%40laumann.xyz>#<[email protected]> talks about a new feature being added to qbe, it's not finalized yet but thought you might be interested in keeping an eye on it
I will take a look after work. Thank you!
Just released v2.0.0 . I think it covers at least of 95% of QBE spec now.