Skip to content

Commit 77f63a2

Browse files
committed
Change field list notation for structs, bug fix for goStmt
1 parent 22ca947 commit 77f63a2

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

glang/coq.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ func (sl *StructLiteral) AddField(field string, value Expr) {
408408
func (sl StructLiteral) Coq(needs_paren bool) string {
409409
var pp buffer
410410
method := "struct.make"
411-
pp.Add("%s %s [", method, StructDesc(sl.StructName).Coq(true))
411+
pp.Add("%s %s [{", method, StructDesc(sl.StructName).Coq(true))
412412
pp.Indent(2)
413413
for i, f := range sl.elts {
414414
terminator := ";"
@@ -418,7 +418,7 @@ func (sl StructLiteral) Coq(needs_paren bool) string {
418418
pp.Add("%s ::= %s%s", quote(f.Field), f.Value.Coq(false), terminator)
419419
}
420420
pp.Indent(-2)
421-
pp.Add("]")
421+
pp.Add("}]")
422422
return addParens(needs_paren, pp.Build())
423423
}
424424

@@ -735,7 +735,7 @@ type SpawnExpr struct {
735735

736736
func (e SpawnExpr) Coq(needs_paren bool) string {
737737
var pp buffer
738-
pp.Block("do: Fork (", "%s)", e.Body.Coq(false))
738+
pp.Block("Fork (", "%s)", e.Body.Coq(false))
739739
return addParens(needs_paren, pp.Build())
740740
}
741741

goose.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ func (ctx Ctx) exprAddr(e ast.Expr) glang.Expr {
11951195
return nil
11961196
}
11971197

1198-
func (ctx Ctx) assignFromTo(s ast.Node, lhs ast.Expr, rhs glang.Expr, cont glang.Expr) glang.Expr {
1198+
func (ctx Ctx) assignFromTo(lhs ast.Expr, rhs glang.Expr, cont glang.Expr) glang.Expr {
11991199
// lhs should either be a map index expression, or is addressable
12001200
switch lhs := lhs.(type) {
12011201
case *ast.Ident:
@@ -1227,7 +1227,7 @@ func (ctx Ctx) assignStmt(s *ast.AssignStmt, cont glang.Expr) glang.Expr {
12271227
intermediates := make([]string, 0, len(s.Lhs))
12281228
for i, lhs := range s.Lhs {
12291229
intermediates = append(intermediates, fmt.Sprintf("$a%d", i))
1230-
e = ctx.assignFromTo(s, lhs, glang.IdentExpr(intermediates[i]), e)
1230+
e = ctx.assignFromTo(lhs, glang.IdentExpr(intermediates[i]), e)
12311231
}
12321232

12331233
// FIXME:(evaluation order)
@@ -1259,25 +1259,21 @@ func (ctx Ctx) assignOpStmt(s *ast.AssignStmt, cont glang.Expr) glang.Expr {
12591259
Op: op,
12601260
Y: ctx.expr(s.Rhs[0]),
12611261
}
1262-
return ctx.assignFromTo(s, s.Lhs[0], rhs, cont)
1262+
return ctx.assignFromTo(s.Lhs[0], rhs, cont)
12631263
}
12641264

12651265
func (ctx Ctx) incDecStmt(stmt *ast.IncDecStmt, cont glang.Expr) glang.Expr {
12661266
op := glang.OpPlus
12671267
if stmt.Tok == token.DEC {
12681268
op = glang.OpMinus
12691269
}
1270-
return ctx.assignFromTo(stmt, stmt.X, glang.BinaryExpr{
1270+
return ctx.assignFromTo(stmt.X, glang.BinaryExpr{
12711271
X: ctx.expr(stmt.X),
12721272
Op: op,
12731273
Y: glang.IntLiteral{Value: 1},
12741274
}, cont)
12751275
}
12761276

1277-
func (ctx Ctx) spawnExpr(thread ast.Expr) glang.SpawnExpr {
1278-
return glang.SpawnExpr{Body: ctx.expr(thread)}
1279-
}
1280-
12811277
func (ctx Ctx) branchStmt(s *ast.BranchStmt, cont glang.Expr) glang.Expr {
12821278
if s.Tok == token.CONTINUE {
12831279
return glang.LetExpr{ValExpr: glang.ContinueExpr{}, Cont: cont}
@@ -1290,15 +1286,15 @@ func (ctx Ctx) branchStmt(s *ast.BranchStmt, cont glang.Expr) glang.Expr {
12901286
}
12911287

12921288
// getSpawn returns a non-nil spawned thread if the expression is a go call
1293-
func (ctx Ctx) goStmt(e *ast.GoStmt) glang.Expr {
1289+
func (ctx Ctx) goStmt(e *ast.GoStmt, cont glang.Expr) glang.Expr {
12941290
args := make([]glang.Expr, 0, len(e.Call.Args))
12951291
for i := range len(e.Call.Args) {
12961292
args = append(args, glang.IdentExpr(fmt.Sprintf("$arg%d", i)))
12971293
}
1298-
var expr glang.Expr = glang.SpawnExpr{Body: glang.NewCallExpr(
1294+
var expr glang.Expr = glang.NewDoSeq(glang.SpawnExpr{Body: glang.NewCallExpr(
12991295
glang.IdentExpr("$go"),
13001296
args...,
1301-
)}
1297+
)}, cont)
13021298
expr = glang.LetExpr{
13031299
Names: []string{"$go"},
13041300
ValExpr: ctx.expr(e.Call.Fun),
@@ -1339,7 +1335,7 @@ func (ctx Ctx) stmt(s ast.Stmt, cont glang.Expr) glang.Expr {
13391335
case *ast.IfStmt:
13401336
return ctx.ifStmt(s, cont)
13411337
case *ast.GoStmt:
1342-
return glang.NewDoSeq(ctx.goStmt(s), cont)
1338+
return ctx.goStmt(s, cont)
13431339
case *ast.ExprStmt:
13441340
return glang.NewDoSeq(ctx.expr(s.X), cont)
13451341
case *ast.AssignStmt:

0 commit comments

Comments
 (0)