Skip to content

Commit

Permalink
Clean up gotimes after test
Browse files Browse the repository at this point in the history
  • Loading branch information
tihardc committed Aug 8, 2024
1 parent a9d0a89 commit 17c5760
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion source/service/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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")
Expand Down
14 changes: 11 additions & 3 deletions source/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
9 changes: 5 additions & 4 deletions source/service/vmmaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (vmm *VmMaker) MakeGoMods(goHandler *GoHandler) {
}
}
}
goHandler.CleanUp()
goHandler.RecordGoTimes()
}

type labeledParsedCodeChunk struct {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 17c5760

Please sign in to comment.