Skip to content

Commit 82f5614

Browse files
committed
feat(stdlib): introduced pot, pot.cmds and pot.deps
1 parent 6fd91b5 commit 82f5614

File tree

18 files changed

+652
-39
lines changed

18 files changed

+652
-39
lines changed

.vscode/launch.json

+15
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@
5454
"LITHIA_STDLIB": "${workspaceFolder}/stdlib"
5555
}
5656
},
57+
{
58+
"name": "lithia run test",
59+
"type": "go",
60+
"request": "launch",
61+
"mode": "auto",
62+
"program": "${workspaceFolder}/app/lithia/main.go",
63+
"args": [
64+
"run",
65+
"test"
66+
],
67+
"cwd": "${workspaceFolder}/examples/greeter",
68+
"env": {
69+
"LITHIA_STDLIB": "${workspaceFolder}/stdlib"
70+
}
71+
},
5772
{
5873
"name": "Launch fib-type",
5974
"type": "go",

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- feat(error): impproved error messages for missing members
99
- feat(stdlib): introduced `apps`
1010
- feat(error): improved error messages for dicts
11+
- feat(stdlib): introduced `pot`, `pot.cmds` and `pot.deps`
1112

1213
## v0.0.18
1314

app/lithia/cmd/run.go

+22-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/spf13/cobra"
88
"github.com/vknabel/lithia"
9+
"github.com/vknabel/lithia/potfile"
910
"github.com/vknabel/lithia/world"
1011
)
1112

@@ -14,24 +15,39 @@ func init() {
1415
}
1516

1617
var runCmd = &cobra.Command{
17-
Use: "run [script]",
18-
Short: "Runs a Lithia script",
19-
Args: cobra.MinimumNArgs(1),
18+
Use: "run [script]",
19+
Short: "Runs a Lithia script",
20+
Args: cobra.MinimumNArgs(1),
21+
DisableFlagParsing: true,
2022
Run: func(cmd *cobra.Command, args []string) {
21-
runFile(args[0], args)
23+
world.Current.Args = args
24+
25+
firstArg := args[0]
26+
potfileState, err := potfile.ForReferenceFile(firstArg)
27+
if err != nil {
28+
fmt.Fprint(world.Current.Stderr, err)
29+
world.Current.Env.Exit(1)
30+
}
31+
32+
if potCmd, ok := potfileState.Cmds[firstArg]; ok {
33+
potCmd.RunCmd(args[1:])
34+
return
35+
}
36+
37+
runFile(firstArg, args)
2238
},
2339
}
2440

2541
func runFile(fileName string, args []string) {
26-
world.Current.Args = args
2742
scriptData, err := world.Current.FS.ReadFile(fileName)
2843
if err != nil {
2944
fmt.Fprint(world.Current.Stderr, err)
3045
world.Current.Env.Exit(1)
3146
}
3247
inter := lithia.NewDefaultInterpreter(path.Dir(fileName))
33-
script := string(scriptData) + "\n"
48+
script := string(scriptData)
3449
_, err = inter.Interpret(fileName, script)
50+
3551
if err != nil {
3652
fmt.Fprint(world.Current.Stderr, err)
3753
world.Current.Env.Exit(1)

examples/greeter/Potfile

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
module potfile
2+
3+
import pot
14
import pot.cmds
5+
import pot.deps
6+
7+
cmds.add "test", { c =>
8+
c.script "cmd/test.lithia"
9+
c.summary "runs all tests"
10+
c.env "LITHIA_TESTS", "1"
11+
c.flag "verbose", { f =>
12+
f.short "v"
13+
f.summary "verbose logging"
14+
}
15+
}
216

3-
cmds.run "test", "cmd/test.lithia"
17+
deps.git "tests", "https://github.com/vknabel/lithia-tests.git", deps.Branch "main"

examples/greeter/cmd/test.lithia

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import tests
44

55
tests.test "example", { fail =>
66
unless True, fail "should never happen"
7-
with type Maybe {
7+
with Some 42, type Maybe {
88
Some: { some => unless some.value == 42, fail "should be 42" },
99
None: { none => fail "none instead of 42" },
1010
Any: { any => fail "should be Some 42" },
11-
}, Some 42
11+
}
1212
}
13+
14+
when tests.enabled, tests.runTests

external/rx/extern-rx-variable.go

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ func (v *RxVariable) Accept(lazyValue runtime.Evaluatable) (runtime.RuntimeValue
5656
if err != nil {
5757
return nil, err
5858
}
59+
if eagerEvaluatable, ok := value.(runtime.EagerEvaluatableRuntimeValue); ok {
60+
err = eagerEvaluatable.EagerEvaluate()
61+
if err != nil {
62+
return nil, err
63+
}
64+
}
5965
v.lock.Lock()
6066
defer v.lock.Unlock()
6167
*v.current = value

0 commit comments

Comments
 (0)