Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/eqci_cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# eqci_cli

Case-insensitive string equality via `eq_ci` density sugar.

```bash
go run ../../howlframe.go -compile-bc eqci_cli.howl
go run ../../howlframe.go -run-bc eqci_cli.howl.bc.bin Hello hello
```
7 changes: 7 additions & 0 deletions apps/eqci_cli/eqci_cli.howl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(do
(let (a (cli_args 0) b (cli_args 1))
(if (or (blank a) (blank b))
(do (print "Usage: eqci_cli <a> <b>") (exit 2))
(if (eq_ci a b)
(do (print "YES") (exit 0))
(do (print "NO") (exit 1))))))
31 changes: 31 additions & 0 deletions apps/eqci_cli/eqci_cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package eqci_cli_test

import (
"os/exec"
"strings"
"testing"
)

func TestEqciCLI(t *testing.T) {
cmd := exec.Command("go", "run", "../../howlframe.go", "-compile-bc", "eqci_cli.howl")
cmd.Dir = "."
if err := cmd.Run(); err != nil {
t.Fatalf("compile: %v", err)
}

cmd = exec.Command("go", "run", "../../howlframe.go", "-run-bc",
"eqci_cli.howl.bc.bin", "Hello", "hello")
cmd.Dir = "."
out, err := cmd.CombinedOutput()
if err != nil || !strings.Contains(string(out), "YES") {
t.Fatalf("yes: %v %s", err, out)
}

cmd = exec.Command("go", "run", "../../howlframe.go", "-run-bc",
"eqci_cli.howl.bc.bin", "Hello", "world")
cmd.Dir = "."
out, err = cmd.CombinedOutput()
if err == nil || !strings.Contains(string(out), "NO") {
t.Fatalf("no: err=%v out=%s", err, out)
}
}
8 changes: 8 additions & 0 deletions apps/getd_cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# getd_cli

JSON key lookup with default via `getd` density sugar.

```bash
go run ../../howlframe.go -compile-bc getd_cli.howl
go run ../../howlframe.go -run-bc -allow-caps filesystem getd_cli.howl.bc.bin sample.json name
```
9 changes: 9 additions & 0 deletions apps/getd_cli/getd_cli.howl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(do
(let (path (cli_args 0) key (cli_args 1) def (cli_args 2))
(if (or (blank path) (blank key))
(do (print "Usage: getd_cli <file> <key> [default]") (exit 2))
(try_let (content (read_text path))
(catch e (do (print "error=" e) (exit 2)))
(try_let (obj (parse_json Any content))
(catch e (do (print "error=" e) (exit 2)))
(print (getd obj key (if (blank def) "MISSING" def))))))))
34 changes: 34 additions & 0 deletions apps/getd_cli/getd_cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package getd_cli_test

import (
"os"
"os/exec"
"strings"
"testing"
)

func TestGetdCLI(t *testing.T) {
cmd := exec.Command("go", "run", "../../howlframe.go", "-compile-bc", "getd_cli.howl")
cmd.Dir = "."
if err := cmd.Run(); err != nil {
t.Fatalf("compile: %v", err)
}
os.WriteFile("sample.json", []byte(`{"name":"ada"}`), 0644)
defer os.Remove("sample.json")

cmd = exec.Command("go", "run", "../../howlframe.go", "-run-bc", "-allow-caps", "filesystem",
"getd_cli.howl.bc.bin", "sample.json", "name")
cmd.Dir = "."
out, err := cmd.CombinedOutput()
if err != nil || !strings.Contains(string(out), "ada") {
t.Fatalf("hit: %v %s", err, out)
}

cmd = exec.Command("go", "run", "../../howlframe.go", "-run-bc", "-allow-caps", "filesystem",
"getd_cli.howl.bc.bin", "sample.json", "missing", "fallback")
cmd.Dir = "."
out, err = cmd.CombinedOutput()
if err != nil || !strings.Contains(string(out), "fallback") {
t.Fatalf("default: %v %s", err, out)
}
}
2 changes: 1 addition & 1 deletion apps/json_get/json_get.howl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(do
(let (path (cli_args 0) key (cli_args 1))
(if (or (= path "") (= key ""))
(if (or (blank path) (blank key))
(do (print "Usage: json_get <file> <key>") (exit 2))
(try_let (content (read_text path))
(catch e (do (print "error=" e) (exit 2)))
Expand Down
8 changes: 8 additions & 0 deletions apps/minmax_cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# minmax_cli

Print min and max of two integers via `min`/`max` density sugar.

```bash
go run ../../howlframe.go -compile-bc minmax_cli.howl
go run ../../howlframe.go -run-bc minmax_cli.howl.bc.bin 3 9
```
8 changes: 8 additions & 0 deletions apps/minmax_cli/minmax_cli.howl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(do
(let (a (cli_args 0) b (cli_args 1))
(if (or (blank a) (blank b))
(do (print "Usage: minmax_cli <a> <b>") (exit 2))
(do
(print (str "min=" (min (to_int a) (to_int b))))
(print (str "max=" (max (to_int a) (to_int b))))
(exit 0)))))
23 changes: 23 additions & 0 deletions apps/minmax_cli/minmax_cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package minmax_cli_test

import (
"os/exec"
"strings"
"testing"
)

func TestMinmaxCLI(t *testing.T) {
cmd := exec.Command("go", "run", "../../howlframe.go", "-compile-bc", "minmax_cli.howl")
cmd.Dir = "."
if err := cmd.Run(); err != nil {
t.Fatalf("compile: %v", err)
}

cmd = exec.Command("go", "run", "../../howlframe.go", "-run-bc",
"minmax_cli.howl.bc.bin", "3", "9")
cmd.Dir = "."
out, err := cmd.CombinedOutput()
if err != nil || !strings.Contains(string(out), "min=3") || !strings.Contains(string(out), "max=9") {
t.Fatalf("minmax: %v %s", err, out)
}
}
7 changes: 3 additions & 4 deletions apps/notes_cli/notes_cli.howl
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
(do
(let (uri (env "NOTES_STORE"))
(do
(store_open kv (if (= uri "") "file://notes.store" uri))
(store_open kv (if (blank uri) "file://notes.store" uri))
(let (a (cli_args) i 0)
(while (< i (list_len a))
(do
(switch (list_get a i)
("add"
(do (inc i)
(let (title (list_get a i) n (to_int (nz (sget kv "next_id") "1")))
(let (title (list_get a i) n (snxt kv "next_id"))
(do
(sput kv (to_string n) title)
(sput kv "next_id" (to_string (+ n 1)))
(sput kv n title)
(print "ADDED" n title)))))
("list"
(for k (store_keys kv)
Expand Down
12 changes: 3 additions & 9 deletions apps/rest_tasks/rest_tasks.howl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
(defun next_id ()
(do
(store_open kv "memory://session")
(let (rec (store_get kv "next_id") n 1)
(do
(if (is_nil rec)
(set n 1)
(set n (to_int (map_get rec "val"))))
(store_put kv "next_id" (dict ("val" (to_string (+ n 1)))))
(return (to_string n))))))
(return (snxt kv "next_id"))))

(route "/tasks" (lambda (req)
(cond
Expand All @@ -25,8 +19,8 @@
((= (req_method req) "POST")
(try_let (body (parse_json Any req.body))
(catch e (res_json 400 (dict ("error" "invalid_json"))))
(let (title (map_get body "title"))
(if (= title "")
(let (title (getd body "title" ""))
(if (blank title)
(res_json 400 (dict ("error" "title_required")))
(let (id (next_id) task (dict ("id" id) ("title" title) ("status" "open")))
(do
Expand Down
42 changes: 9 additions & 33 deletions apps/task_api/task_api.howl
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,20 @@
(defun next_task_id ()
(do
(store_open kv "memory://session")
(let (rec (store_get kv "next_id"))
(let (n 1)
(do
(if (is_nil rec)
(set n 1)
(let (v (map_get rec "val"))
(set n (to_int v))
)
)
(store_put kv "next_id" (dict ("val" (to_string (+ n 1)))))
(return (to_string n))
)
)
)
)
)
(return (snxt kv "next_id"))))

(route "/tasks/create" (lambda (req)
(try_let (body (parse_json TaskInput req.body))
(catch parse_err
(res_json 400 (dict ("error" "invalid_json")))
)
(let (title (map_get body "title"))
(if (= title "")
(res_json 400 (dict ("error" "invalid_json"))))
(let (title (getd body "title" ""))
(if (blank title)
(res_json 400 (dict ("error" "title_required")))
(let (id (call next_task_id))
(let (task (dict ("id" id) ("title" title) ("status" "open")))
(do
(store_open kv "memory://session")
(store_put kv id task)
(res_json 201 task)
)
)
)
)
)
)
))
(let (id (call next_task_id) task (dict ("id" id) ("title" title) ("status" "open")))
(do
(store_open kv "memory://session")
(store_put kv id task)
(res_json 201 task))))))))

(route "/tasks/list" (lambda (req)
(do
Expand Down
23 changes: 11 additions & 12 deletions apps/webhook_relay/webhook_relay.howl
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
(http_server 8098
(route "/relay" (lambda (req)
(let (upstream (env "UPSTREAM_URL"))
(if (= upstream "")
(if (blank upstream)
(res_json 500 (dict ("error" "missing_UPSTREAM_URL")))
(let (method (req_method req))
(cond
((= method "GET")
(let (r (http_request upstream "GET"))
(http_res r)))
((= method "POST")
(try_let (body (parse_json Any req.body))
(catch e (res_json 400 (dict ("error" "invalid_json"))))
(let (r (http_request upstream "POST" (encode_json body)))
(http_res r))))
(else (res_json 405 (dict ("error" "method_not_allowed")))))))))))
(switch (req_method req)
("GET"
(let (r (http_request upstream "GET"))
(http_res r)))
("POST"
(try_let (body (parse_json Any req.body))
(catch e (res_json 400 (dict ("error" "invalid_json"))))
(let (r (http_request upstream "POST" (encode_json body)))
(http_res r))))
(else (res_json 405 (dict ("error" "method_not_allowed"))))))))))
24 changes: 24 additions & 0 deletions benchmarks/real_apps/eqci_cli/go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"fmt"
"os"
"strings"
)

func main() {
os.Exit(run(os.Args[1:]))
}

func run(args []string) int {
if len(args) < 2 || args[0] == "" || args[1] == "" {
fmt.Println("Usage: eqci_cli <a> <b>")
return 2
}
if strings.EqualFold(args[0], args[1]) {
fmt.Println("YES")
return 0
}
fmt.Println("NO")
return 1
}
17 changes: 17 additions & 0 deletions benchmarks/real_apps/eqci_cli/node/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

function main(argv) {
const args = argv.slice(2);
if (args.length < 2 || args[0] === "" || args[1] === "") {
console.log("Usage: eqci_cli <a> <b>");
return 2;
}
if (args[0].toLowerCase() === args[1].toLowerCase()) {
console.log("YES");
return 0;
}
console.log("NO");
return 1;
}

process.exit(main(process.argv));
17 changes: 17 additions & 0 deletions benchmarks/real_apps/eqci_cli/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3
import sys


def main(argv: list[str]) -> int:
if len(argv) < 3 or argv[1] == "" or argv[2] == "":
print("Usage: eqci_cli <a> <b>")
return 2
if argv[1].lower() == argv[2].lower():
print("YES")
return 0
print("NO")
return 1


if __name__ == "__main__":
raise SystemExit(main(sys.argv))
38 changes: 38 additions & 0 deletions benchmarks/real_apps/getd_cli/go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"encoding/json"
"fmt"
"os"
)

func main() {
os.Exit(run(os.Args[1:]))
}

func run(args []string) int {
if len(args) < 2 || args[0] == "" || args[1] == "" {
fmt.Println("Usage: getd_cli <file> <key> [default]")
return 2
}
def := "MISSING"
if len(args) > 2 && args[2] != "" {
def = args[2]
}
raw, err := os.ReadFile(args[0])
if err != nil {
fmt.Printf("error=%v\n", err)
return 2
}
var obj map[string]any
if err := json.Unmarshal(raw, &obj); err != nil {
fmt.Printf("error=%v\n", err)
return 2
}
if v, ok := obj[args[1]]; ok {
fmt.Println(v)
return 0
}
fmt.Println(def)
return 0
}
Loading
Loading