From 349a5838f75a34d47d465538cdd19cbbc307def7 Mon Sep 17 00:00:00 2001 From: Upamanyu Sharma Date: Tue, 17 Dec 2024 14:59:28 -0500 Subject: [PATCH] Use `package_init` in translation --- goose.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/goose.go b/goose.go index 29b59c1..512e95b 100644 --- a/goose.go +++ b/goose.go @@ -2478,7 +2478,7 @@ func (ctx *Ctx) initFunctions() []glang.Decl { ctx.dep.setCurrentName("initialize'") initFunc := glang.FuncDecl{Name: "initialize'"} - ctx.dep.addDep("define'") + e = nil // add all init() function bodies @@ -2550,20 +2550,20 @@ func (ctx *Ctx) initFunctions() []glang.Decl { } } + ctx.dep.addDep("define'") e = glang.NewDoSeq(glang.NewCallExpr(glang.GallinaIdent("define'"), glang.Tt), e) for _, importName := range ctx.importNames { e = glang.NewDoSeq(glang.GallinaIdent(importName+"."+"initialize'"), e) } - e = glang.IfExpr{ - Cond: glang.NewCallExpr(glang.GallinaIdent("globals.is_uninitialized"), - glang.GallinaIdent("pkg_name'")), - Then: e, - Else: glang.DoExpr{Expr: glang.Tt}, - } + e = glang.NewCallExpr(glang.GallinaIdent("exception_do"), e) + e = glang.NewCallExpr(glang.GallinaIdent("globals.package_init"), + glang.GallinaIdent("pkg_name'"), + glang.FuncLit{Args: nil, Body: e}, + ) - initFunc.Body = glang.NewCallExpr(glang.GallinaIdent("exception_do"), e) + initFunc.Body = e return []glang.Decl{packageIdDecl, defineFunc, initFunc} }