From 17c576020c256c60a7599188d0aaf2e134129ea2 Mon Sep 17 00:00:00 2001 From: Tim Hardcastle Date: Wed, 7 Aug 2024 22:55:57 -0700 Subject: [PATCH] Clean up gotimes after test --- source/service/golang.go | 3 ++- source/service/service_test.go | 14 +++++++++++--- source/service/vmmaker.go | 9 +++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/source/service/golang.go b/source/service/golang.go index 2accfcb3..b99b4565 100644 --- a/source/service/golang.go +++ b/source/service/golang.go @@ -62,7 +62,7 @@ func NewGoHandler(prsr *parser.Parser) *GoHandler { return &gh } -func (gh *GoHandler) CleanUp() { +func (gh *GoHandler) RecordGoTimes() { // We add the newly compiled modules to the list of times. @@ -76,6 +76,7 @@ func (gh *GoHandler) CleanUp() { gh.timeMap[k] = int(modifiedTime) } // And then write out the list of times to the .dat file. + f, err := os.Create(gh.Prsr.Directory + "rsc/go/gotimes.dat") if err != nil { panic("Can't create file rsc/go/gotimes.dat") diff --git a/source/service/service_test.go b/source/service/service_test.go index 4362d67b..095bb383 100644 --- a/source/service/service_test.go +++ b/source/service/service_test.go @@ -286,18 +286,26 @@ func TestGocode(t *testing.T) { {`constructPerson "Doug", 42`, `Person with (name::"Doug", age::42)`}, {`deconstructPerson Person "Doug", 42`, `("Doug", 42)`}, } + currentDirectory, _ := os.Getwd() + absolutePathToRscGo, _ := filepath.Abs(currentDirectory + "/../../rsc/go/") + locationOfGoTimes := absolutePathToRscGo + "/gotimes.dat" + temp, err := os.ReadFile(locationOfGoTimes) + if err != nil { + println("Couldn't read gotimes") + println("Error was", err.Error()) + panic("That's all folks!") + } RunTest(t, "gocode_test.pf", tests, testValues) // Tear down the .go and .so files. nameOfTestFile := "gocode_test.pf" - currentDirectory, _ := os.Getwd() locationOfGocode, _ := filepath.Abs(currentDirectory + "/../../gocode 1.go") os.Remove(locationOfGocode) - absolutePathToGoTestFile, _ := filepath.Abs(currentDirectory + "/../../rsc/go/") absoluteLocationOfPipefishTestFile, _ := filepath.Abs(currentDirectory + "/test-files/" + nameOfTestFile) file, _ := os.Stat(absoluteLocationOfPipefishTestFile) timestamp := file.ModTime().UnixMilli() - goTestFile := absolutePathToGoTestFile + "/" + text.Flatten(absoluteLocationOfPipefishTestFile) + "_" + strconv.Itoa(int(timestamp)) + ".so" + goTestFile := absolutePathToRscGo + "/" + text.Flatten(absoluteLocationOfPipefishTestFile) + "_" + strconv.Itoa(int(timestamp)) + ".so" os.Remove(goTestFile) + os.WriteFile(locationOfGoTimes, temp, 0644) } func TestImports(t *testing.T) { tests := []TestItem{ diff --git a/source/service/vmmaker.go b/source/service/vmmaker.go index e0d1f048..34ab6ea1 100644 --- a/source/service/vmmaker.go +++ b/source/service/vmmaker.go @@ -283,7 +283,7 @@ func (vmm *VmMaker) MakeGoMods(goHandler *GoHandler) { } } } - goHandler.CleanUp() + goHandler.RecordGoTimes() } type labeledParsedCodeChunk struct { @@ -392,9 +392,9 @@ func (vmm *VmMaker) compileEverything() [][]labeledParsedCodeChunk { for _, dec := range groupOfDeclarations { switch dec.decType { case functionDeclaration: - vmm.compileFunction(vmm.cp.P.ParsedDeclarations[functionDeclaration][dec.decNumber], vmm.uP.isPrivate(int(dec.decType), dec.decNumber), vmm.cp.GlobalConsts, functionDeclaration, vmm.cp.logFlavor) + vmm.compileFunction(vmm.cp.P.ParsedDeclarations[functionDeclaration][dec.decNumber], vmm.uP.isPrivate(int(dec.decType), dec.decNumber), vmm.cp.GlobalConsts, functionDeclaration) case commandDeclaration: - vmm.compileFunction(vmm.cp.P.ParsedDeclarations[commandDeclaration][dec.decNumber], vmm.uP.isPrivate(int(dec.decType), dec.decNumber), vmm.cp.GlobalVars, commandDeclaration, vmm.cp.logFlavor) + vmm.compileFunction(vmm.cp.P.ParsedDeclarations[commandDeclaration][dec.decNumber], vmm.uP.isPrivate(int(dec.decType), dec.decNumber), vmm.cp.GlobalVars, commandDeclaration) } vmm.uP.fnIndex[fnSource{dec.decType, dec.decNumber}].Number = uint32(len(vmm.cp.Fns) - 1) } @@ -1057,7 +1057,8 @@ func (vmm *VmMaker) addAbstractTypesToVm() { } // For compiling a top-level function. -func (vmm *VmMaker) compileFunction(node ast.Node, private bool, outerEnv *Environment, dec declarationType, logFlavor LogFlavor) *CpFunc { +func (vmm *VmMaker) compileFunction(node ast.Node, private bool, outerEnv *Environment, dec declarationType) *CpFunc { + logFlavor := vmm.cp.logFlavor if info, functionExists := vmm.cp.getDeclaration(decFUNCTION, node.GetToken(), DUMMY); functionExists { vmm.cp.Fns = append(vmm.cp.Fns, info.(*CpFunc)) return info.(*CpFunc)