Skip to content

Commit

Permalink
Update for Gleam 0.34
Browse files Browse the repository at this point in the history
  • Loading branch information
Willyboar committed Feb 3, 2024
1 parent 0e8acb6 commit 4578f8d
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 205 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.5.3
- uses: erlef/setup-beam@v1.15.3
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: "25.2"
gleam-version: "0.30.5"
otp-version: "26.0.2"
gleam-version: "0.34.1"
rebar3-version: "3"
# elixir-version: "1.14.2"
- run: gleam format --check src test
# elixir-version: "1.15.4"
- run: gleam deps download
- run: gleam test
- run: gleam format --check src test

6 changes: 3 additions & 3 deletions gleam.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name = "glove"
version = "0.3.0"
version = "0.4.0"
description = "Gleam QBE IR Generator"
licences = ["MIT"]
repository = { type = "github", user = "Willyboar", repo = "glove" }

[dependencies]
gleam_stdlib = "~> 0.30"
gleam_stdlib = "~> 0.34 or ~> 1.0"

[dev-dependencies]
gleeunit = "~> 0.10"
gleeunit = "~> 1.0"
8 changes: 4 additions & 4 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_stdlib", version = "0.30.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "03710B3DA047A3683117591707FCA19D32B980229DD8CE8B0603EB5B5144F6C3" },
{ name = "gleeunit", version = "0.10.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "ECEA2DE4BE6528D36AFE74F42A21CDF99966EC36D7F25DEB34D47DD0F7977BAF" },
{ name = "gleam_stdlib", version = "0.34.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "1FB8454D2991E9B4C0C804544D8A9AD0F6184725E20D63C3155F0AEB4230B016" },
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
]

[requirements]
gleam_stdlib = { version = "~> 0.30" }
gleeunit = { version = "~> 0.10" }
gleam_stdlib = { version = "~> 0.34 or ~> 1.0" }
gleeunit = { version = "~> 1.0" }
133 changes: 97 additions & 36 deletions src/glove.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gleam/int
import gleam/string
import gleam/option.{None, Option, Some}
import gleam/option.{type Option, None, Some}
import gleam/list

/// QBE Comparison Operators
Expand Down Expand Up @@ -83,29 +83,59 @@ pub fn display_inst(inst: Inst) -> String {
_ ->
case cmp {
Slt ->
"c" <> "slt" <> " " <> display_type(ty) <> " " <> display_value(a) <> " " <> display_value(
b,
)
"c"
<> "slt"
<> " "
<> display_type(ty)
<> " "
<> display_value(a)
<> " "
<> display_value(b)
Sle ->
"c" <> "sle" <> " " <> display_type(ty) <> " " <> display_value(a) <> " " <> display_value(
b,
)
"c"
<> "sle"
<> " "
<> display_type(ty)
<> " "
<> display_value(a)
<> " "
<> display_value(b)
Sgt ->
"c" <> "sgt" <> " " <> display_type(ty) <> " " <> display_value(a) <> " " <> display_value(
b,
)
"c"
<> "sgt"
<> " "
<> display_type(ty)
<> " "
<> display_value(a)
<> " "
<> display_value(b)
Sge ->
"c" <> "sge" <> " " <> display_type(ty) <> " " <> display_value(a) <> " " <> display_value(
b,
)
"c"
<> "sge"
<> " "
<> display_type(ty)
<> " "
<> display_value(a)
<> " "
<> display_value(b)
Eq ->
"c" <> "eq" <> " " <> display_type(ty) <> " " <> display_value(a) <> " " <> display_value(
b,
)
"c"
<> "eq"
<> " "
<> display_type(ty)
<> " "
<> display_value(a)
<> " "
<> display_value(b)
Ne ->
"c" <> "ne" <> " " <> display_type(ty) <> " " <> display_value(a) <> " " <> display_value(
b,
)
"c"
<> "ne"
<> " "
<> display_type(ty)
<> " "
<> display_value(a)
<> " "
<> display_value(b)
}
}
}
Expand All @@ -124,7 +154,7 @@ pub fn display_inst(inst: Inst) -> String {
Call(name, args) -> {
let arg_str =
args
|> list.index_map(fn(_, arg) {
|> list.index_map(fn(arg, _) {
case arg {
#(ty, val) -> display_type(ty) <> " " <> display_value(val)
}
Expand All @@ -141,9 +171,12 @@ pub fn display_inst(inst: Inst) -> String {
case typ {
Aggregate(_) -> "Store to an aggregate type"
_ ->
"store" <> display_type(typ) <> " " <> display_value(value) <> " " <> display_value(
dest,
)
"store"
<> display_type(typ)
<> " "
<> display_value(value)
<> " "
<> display_value(dest)
}

Load(typ, val) ->
Expand All @@ -152,9 +185,12 @@ pub fn display_inst(inst: Inst) -> String {
_ -> "load" <> display_type(typ) <> " " <> display_value(val)
}
Blit(src, dest, n) ->
"blit " <> display_value(src) <> ", " <> display_value(dest) <> ", " <> int.to_string(
n,
)
"blit "
<> display_value(src)
<> ", "
<> display_value(dest)
<> ", "
<> int.to_string(n)
}
}

Expand Down Expand Up @@ -233,6 +269,7 @@ pub fn size(self) -> Int {
Aggregate(td) ->
case td.items {
[] -> 0
[_, ..] -> 1
}
}
}
Expand Down Expand Up @@ -261,14 +298,21 @@ pub fn display_data_def(def: DataDef) -> String {

let items_str =
def.items
|> list.index_map(fn(_, item) {
|> list.index_map(fn(item, _) {
case item {
#(ty, di) -> display_type(ty) <> " " <> display_data_item(di)
}
})
|> string.join(", ")

linkage_str <> "data $" <> def.name <> " =" <> align_str <> " { " <> items_str <> " }"
linkage_str
<> "data $"
<> def.name
<> " ="
<> align_str
<> " { "
<> items_str
<> " }"
}

/// QBE aggregate type definition
Expand All @@ -285,7 +329,7 @@ pub fn display_type_def(def: TypeDef) -> String {

let items_str =
def.items
|> list.index_map(fn(_, item) {
|> list.index_map(fn(item, _) {
case item {
#(ty, count) ->
case count > 1 {
Expand Down Expand Up @@ -333,9 +377,11 @@ pub type Statement {
pub fn display_statement(stmt: Statement) -> String {
case stmt {
Assign(val, typ, inst) ->
display_value(val) <> " =" <> display_type(typ) <> " " <> display_inst(
inst,
)
display_value(val)
<> " ="
<> display_type(typ)
<> " "
<> display_inst(inst)
Volatile(inst) -> display_inst(inst)
}
}
Expand Down Expand Up @@ -412,7 +458,18 @@ pub fn display_function(func: Function) -> String {
let args_str = display_arguments(func.arguments)
let blocks_str = display_blocks(func.blocks)

linkage_str <> "function" <> return_str <> " " <> "$" <> name_str <> "(" <> args_str <> ")" <> " {\n" <> blocks_str <> "}"
linkage_str
<> "function"
<> return_str
<> " "
<> "$"
<> name_str
<> "("
<> args_str
<> ")"
<> " {\n"
<> blocks_str
<> "}"
}

/// Display functions Arguments
Expand All @@ -421,7 +478,7 @@ pub fn display_arguments(arguments: List(#(Type, Value))) -> String {
[] -> ""
_ ->
arguments
|> list.index_map(fn(_, arg) {
|> list.index_map(fn(arg, _) {
case arg {
#(ty, val) -> display_type(ty) <> " " <> display_value(val)
}
Expand Down Expand Up @@ -476,10 +533,14 @@ pub fn display_linkage(linkage: Linkage) -> String {
}
let section_str = case linkage.section {
Some(section) ->
"section \"" <> section <> "\"" <> case linkage.secflags {
"section \""
<> section
<> "\""
<> case linkage.secflags {
Some(secflags) -> " \"" <> secflags <> "\""
None -> ""
} <> " "
}
<> " "
None -> ""
}
exported_str <> section_str
Expand Down
Loading

0 comments on commit 4578f8d

Please sign in to comment.