Skip to content

Commit c6058ab

Browse files
committed
Handle machine vs primitive in one more place
1 parent b741d73 commit c6058ab

File tree

6 files changed

+17
-35
lines changed

6 files changed

+17
-35
lines changed

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/goose-lang/goose
22

3-
go 1.21
3+
go 1.22
44

55
require (
66
github.com/fatih/color v1.17.0
@@ -13,6 +13,7 @@ require (
1313

1414
require (
1515
github.com/davecgh/go-spew v1.1.1 // indirect
16+
github.com/goose-lang/primitive v0.1.0
1617
github.com/goose-lang/std v0.3.2 // indirect
1718
github.com/mattn/go-colorable v0.1.13 // indirect
1819
github.com/mattn/go-isatty v0.0.20 // indirect

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
44
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
5+
github.com/goose-lang/primitive v0.1.0 h1:JReOdFzUdGD7f8nWTC/uOlNpBdVFU4q8HzMSgn8edaY=
6+
github.com/goose-lang/primitive v0.1.0/go.mod h1:sDE72zVH81ASwPXc1m9OgSfaaY0aZHu4Ty19FgONpOc=
57
github.com/goose-lang/std v0.3.2 h1:dYnOsrrbfSG5Bx/rE/X2PylIX6ObTavUosXqzbIzRys=
68
github.com/goose-lang/std v0.3.2/go.mod h1:0IoDUCIC80Msc7h/SqpbZY1ytjhV39rgKnyHG/tjdis=
79
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=

goose.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ func (ctx Ctx) prophIdMethod(f *ast.SelectorExpr, args []ast.Expr) coq.CallExpr
368368
case "ResolveBool", "ResolveU64":
369369
return ctx.newCoqCall("ResolveProph", callArgs)
370370
default:
371-
ctx.unsupported(f, "method %s of machine.ProphId", f.Sel.Name)
371+
ctx.unsupported(f, "method %s of primitive.ProphId", f.Sel.Name)
372372
return coq.CallExpr{}
373373
}
374374
}
@@ -411,7 +411,7 @@ func (ctx Ctx) packageMethod(f *ast.SelectorExpr,
411411
case "NewProph":
412412
return ctx.newCoqCall("NewProph", args)
413413
default:
414-
ctx.futureWork(f, "unhandled call to machine.%s", f.Sel.Name)
414+
ctx.futureWork(f, "unhandled call to primitive.%s", f.Sel.Name)
415415
return coq.CallExpr{}
416416
}
417417
}

machine/prims.go

+3-16
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"os"
1111
"sync"
1212
"time"
13+
14+
"github.com/goose-lang/primitive"
1315
)
1416

1517
// UInt64Get converts the first 8 bytes of p to a uint64.
@@ -96,22 +98,7 @@ func Exit(n uint64) {
9698
// Not provided by sync.Cond, so we have to (inefficiently) implement this
9799
// ourselves.
98100
func WaitTimeout(cond *sync.Cond, timeoutMs uint64) {
99-
done := make(chan struct{})
100-
go func() {
101-
cond.Wait()
102-
cond.L.Unlock()
103-
close(done)
104-
}()
105-
select {
106-
case <-time.After(time.Duration(timeoutMs) * time.Millisecond):
107-
// timed out
108-
cond.L.Lock()
109-
return
110-
case <-done:
111-
// Wait returned
112-
cond.L.Lock()
113-
return
114-
}
101+
primitive.WaitTimeout(cond, timeoutMs)
115102
}
116103

117104
func TimeNow() uint64 {

machine/proph.go

+6-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
package machine
22

3-
// Prophecy variables.
4-
//
5-
// We represent the name of a prophecy variable via an opaque type. In Go, it
6-
// does not actually carry any data, but in GooseLang we store the ProphId.
7-
// However, making a type opaque in Go seems to be tricky. Let's hope adding a
8-
// private field helps.
9-
//
10-
//lint:ignore U1000 p is unused, see above comment.
11-
type prophId struct{ p struct{} }
12-
type ProphId = *prophId
3+
// Wrap goose-lang/primitive for backwards compatibility
4+
5+
import "github.com/goose-lang/primitive"
6+
7+
type ProphId = primitive.ProphId
138

149
func NewProph() ProphId {
15-
return &prophId{}
10+
return primitive.NewProph()
1611
}
17-
18-
func (p ProphId) ResolveBool(b bool) {}
19-
func (p ProphId) ResolveU64(i uint64) {}

types.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func isProphId(t types.Type) bool {
249249
if t, ok := t.(*types.Pointer); ok {
250250
if t, ok := t.Elem().(*types.Named); ok {
251251
name := t.Obj()
252-
return name.Pkg().Name() == "machine" &&
252+
return (name.Pkg().Name() == "machine" || name.Pkg().Name() == "primitive") &&
253253
name.Name() == "prophId"
254254
}
255255
}
@@ -275,7 +275,7 @@ func isString(t types.Type) bool {
275275
func isDisk(t types.Type) bool {
276276
if t, ok := t.(*types.Named); ok {
277277
obj := t.Obj()
278-
if obj.Pkg().Path() == "github.com/goose-lang/goose/machine/disk" &&
278+
if (obj.Pkg().Path() == "github.com/goose-lang/goose/machine/disk" || obj.Pkg().Path() == "github.com/goose-lang/primitive/disk") &&
279279
obj.Name() == "Disk" {
280280
return true
281281
}

0 commit comments

Comments
 (0)