Go
HIR projection with file emission and end-to-end floors.
Part of the HIR lane. Every panel below is compiler output.
How to read it#
Go has no generics-free way to express some Faber types, so the emitter materialises helpers the source never wrote. Borrow modes (ref / mut / from) erase here — they lower, but they do not survive as distinctions.
Measured support#
| Capable | Analyzable | Coverage |
|---|---|---|
| 514 | 573 | 90% |
From the target matrix: how many corpus exempla lower to this target. Coverage is not a quality score — an emitter can lower a term and still erase a distinction.
Not fully supported#
Terms the matrix records as partial, planned, or unsupported for this target. A term here is a measured gap, not an omission.
| Category | Terms |
|---|---|
| Keywords — application lane | <a id="ad"></a>call, <a id="itera"></a>for, <a id="numerus"></a>int |
| Operators — application lane | <a id="modulus-u16"></a>wrapping<u16>, <a id="modulus-u32"></a>wrapping<u32>, <a id="modulus-u64"></a>wrapping<u64>, <a id="modulus-u8"></a>wrapping<u8>, <a id="whole-width-range"></a>whole-width range, <a id="wrapping-w-lo-hi"></a>wrapping<W, lo ‥ hi>, ·, ×, ‥, ↦, ⊗, ⊙ |
Typed tensors#
Builds two shaped matrices, multiplies them, and reduces the product to a scalar. Exercises shape-bearing types and a reduction.
Faber source
faber convert --to en — English reader surfacemain {
let list<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
let list<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
let tf32[2, 3] a ← flat_a ↦ tensor<f32, [2, 3]>
let tf32[3, 4] b ← flat_b ↦ tensor<f32, [3, 4]>
let tf32[2, 4] product ← a.matmul(b)
let f32 mean ← product.mean()
print mean
}faber convert --to la — canonical Faberincipit {
sit lista<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
sit lista<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
sit tf32[2, 3] a ← flat_a ↦ tensor<f32, [2, 3]>
sit tf32[3, 4] b ← flat_b ↦ tensor<f32, [3, 4]>
sit tf32[2, 4] product ← a.matmul(b)
sit f32 mean ← product.media()
nota mean
}faber convert --to th-TH — Thaiเริ่ม {
กำหนด รายการ<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
กำหนด รายการ<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
กำหนด tf32[2, 3] a ← flat_a ↦ เทนเซอร์<f32, [2, 3]>
กำหนด tf32[3, 4] b ← flat_b ↦ เทนเซอร์<f32, [3, 4]>
กำหนด tf32[2, 4] product ← a.คูณเมทริกซ์(b)
กำหนด f32 mean ← product.ค่าเฉลี่ย()
บันทึก mean
}faber convert --to zh-Hans — Simplified Chinese入口 {
设 列表<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
设 列表<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
设 tf32[2, 3] a ← flat_a ↦ 张量<f32, [2, 3]>
设 tf32[3, 4] b ← flat_b ↦ 张量<f32, [3, 4]>
设 tf32[2, 4] product ← a.矩阵乘法(b)
设 f32 mean ← product.均值()
显示 mean
}faber convert --to zh-Hant — Traditional Chinese入口 {
設為 列表<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
設為 列表<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
設為 tf32[2, 3] a ← flat_a ↦ 張量<f32, [2, 3]>
設為 tf32[3, 4] b ← flat_b ↦ 張量<f32, [3, 4]>
設為 tf32[2, 4] product ← a.矩陣乘法(b)
設為 f32 mean ← product.平均值()
註記 mean
}faber convert --to vi — Vietnamesebắt_đầu {
đặt danh_sách<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
đặt danh_sách<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
đặt tf32[2, 3] a ← flat_a ↦ ten_xo<f32, [2, 3]>
đặt tf32[3, 4] b ← flat_b ↦ ten_xo<f32, [3, 4]>
đặt tf32[2, 4] product ← a.nhân_ma_trận(b)
đặt f32 mean ← product.trung_bình()
ghi_chú mean
}faber convert --to ar — Arabicبداية {
ليكن قائمة<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
ليكن قائمة<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
ليكن tf32[2, 3] a ← flat_a ↦ موتر<f32, [2, 3]>
ليكن tf32[3, 4] b ← flat_b ↦ موتر<f32, [3, 4]>
ليكن tf32[2, 4] product ← a.ضرب_المصفوفات(b)
ليكن f32 mean ← product.المتوسط()
اعرض mean
}faber convert --to hi — Hindiआरंभ {
बैठा सूची<f32> flat_a ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
बैठा सूची<f32> flat_b ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
बैठा tf32[2, 3] a ← flat_a ↦ टेंसर<f32, [2, 3]>
बैठा tf32[3, 4] b ← flat_b ↦ टेंसर<f32, [3, 4]>
बैठा tf32[2, 4] product ← a.आव्यूह_गुणन(b)
बैठा f32 mean ← product.माध्य()
दिखाओ mean
}Go — 9 lines in, 21 out (2.3×)
// Code generated by faber. DO NOT EDIT.
package main
import (
"faber/rt"
"fmt"
"strconv"
"strings"
)
func main() {
defer rt.TrapHandle()
l_flat_a := []float32{float32(1.0), float32(2.0), float32(3.0), float32(4.0), float32(5.0), float32(6.0)}
l_flat_b := []float32{float32(1.0), float32(2.0), float32(3.0), float32(4.0), float32(5.0), float32(6.0), float32(7.0), float32(8.0), float32(9.0), float32(10.0), float32(11.0), float32(12.0)}
l_a := rt.TensorTensor[float32]{}.Strue(func() []float32 { src := l_flat_a; out := make([]float32, len(src)); for i, value := range src { out[i] = value }; return out }(), []int{2, 3})
l_b := rt.TensorTensor[float32]{}.Strue(func() []float32 { src := l_flat_b; out := make([]float32, len(src)); for i, value := range src { out[i] = value }; return out }(), []int{3, 4})
l_product := l_a.Matmul(l_b)
l_mean := float32(l_product.Media())
fmt.Println(func(v float32) string { s := strconv.FormatFloat(float64(v), 'f', -1, 32); if s == "NaN" { return s }; if s == "+Inf" { return "inf" }; if s == "-Inf" { return "-inf" }; if !strings.Contains(s, ".") { return s + ".0" }; return s }(float32(l_mean)))
}The error channel#
A function that may fail, and a caller that catches. Shows how the ⇥ channel becomes each target's own error idiom.
Faber source
faber convert --to en — English reader surfacefn divide(int a, int b) → int ⇥ string {
if b ≡ 0 {
throw "division by zero"
}
return a / b
}
main {
do {
print divide(10, 2)
}
catch err {
warn err
}
}faber convert --to la — canonical Faberfunctio divide(numerus a, numerus b) → numerus ⇥ textus {
si b ≡ 0 {
iace "division by zero"
}
redde a / b
}
incipit {
fac {
nota divide(10, 2)
}
cape err {
mone err
}
}faber convert --to th-TH — Thaiฟังก์ชัน divide(จํานวน a, จํานวน b) → จํานวน ⇥ ข้อความ {
ถ้า b ≡ 0 {
โยน "division by zero"
}
คืน a / b
}
เริ่ม {
ทำ {
บันทึก divide(10, 2)
}
จับ err {
เตือน err
}
}faber convert --to zh-Hans — Simplified Chinese函数 divide(整数 a, 整数 b) → 整数 ⇥ 文本 {
如果 b ≡ 0 {
抛错 "division by zero"
}
返回 a / b
}
入口 {
执行 {
显示 divide(10, 2)
}
捕获 err {
警告 err
}
}faber convert --to zh-Hant — Traditional Chinese函式 divide(整數 a, 整數 b) → 整數 ⇥ 文字 {
若 b ≡ 0 {
拋出 "division by zero"
}
傳回 a / b
}
入口 {
執行 {
註記 divide(10, 2)
}
捕捉 err {
警告 err
}
}faber convert --to vi — Vietnamesehàm divide(số a, số b) → số ⇥ văn_bản {
nếu b ≡ 0 {
ném "division by zero"
}
trả a / b
}
bắt_đầu {
làm {
ghi_chú divide(10, 2)
}
bắt err {
cảnh_báo err
}
}faber convert --to ar — Arabicدالة divide(عدد a, عدد b) → عدد ⇥ نص {
إذا b ≡ 0 {
ارم "division by zero"
}
أعد a / b
}
بداية {
افعل {
اعرض divide(10, 2)
}
التقط err {
نبه err
}
}faber convert --to hi — Hindiफलन divide(संख्या a, संख्या b) → संख्या ⇥ पाठ {
यदि b ≡ 0 {
इधरफेंको "division by zero"
}
लौटाओ a / b
}
आरंभ {
करो {
दिखाओ divide(10, 2)
}
पकड़ो err {
चेताओ err
}
}Go — 13 lines in, 31 out (2.4×)
// Code generated by faber. DO NOT EDIT.
package main
import (
"errors"
"faber/rt"
"fmt"
"os"
)
func divide(p_a int, p_b int) (int, error) {
if (p_b == 0) {
return 0, errors.New("division by zero")
}
return int(rt.ExactStore[int64](rt.ExactDiv(rt.ExactI(int64(p_a)), rt.ExactI(int64(p_b))), "return")), nil
}
func main() {
defer rt.TrapHandle()
if l_err := func() error {
v0, r0 := divide(10, 2)
if r0 != nil {
return r0
}
fmt.Println(v0)
return nil
}(); l_err != nil {
fmt.Fprintln(os.Stderr, l_err.Error())
}
}Collections and iteration#
A list folded to a total with for from. The plainest possible read on how loops lower.
Faber source
fn sum(list<int> numeri) → int {
mut int total ← 0
for from numeri let n {
total ← total + n
}
return total
}
main {
let list<int> valores ← [1, 2, 3, 4, 5]
print sum(valores)
}Go — 12 lines in, 22 out (1.8×)
// Code generated by faber. DO NOT EDIT.
package main
import (
"faber/rt"
"fmt"
)
func sum(p_numeri []int) int {
l_total := 0
for _, l_n := range p_numeri {
l_total = int(rt.ExactStore[int64](rt.ExactAdd(rt.ExactI(int64(l_total)), rt.ExactI(int64(l_n))), "assignment to `total`"))
}
return l_total
}
func main() {
defer rt.TrapHandle()
l_valores := []int{1, 2, 3, 4, 5}
fmt.Println(sum(l_valores))
}---