@@ -64,7 +64,7 @@ async function parseOptFunctions(inputFile: WorkspaceFile) {
64
64
65
65
import * as fs from 'fs' ;
66
66
67
- export async function mergeModifiedFunction ( code : string , funs : { code : string , name : string } [ ] , new_code : string ) {
67
+ export async function mergeModifiedFunction ( code : string , funs : { code : string , name : string } [ ] , new_code : string ) {
68
68
let name = function_name_from_code ( new_code ) ;
69
69
let fun = funs . find ( f => f . name === name ) ;
70
70
if ( fun ) {
@@ -74,30 +74,32 @@ export async function mergeModifiedFunction(code :string, funs : { code: string,
74
74
return code ;
75
75
}
76
76
77
- async function canCompileCode ( inputFile : WorkspaceFile , code : string ) {
77
+ async function canCompileCode ( inputFile : WorkspaceFile , new_code : string ) {
78
78
79
+ //
79
80
// move input file to a temp file
80
81
// move code to the inputFile.filename
81
82
// invoke ninja in the build directory: ninja -b build
82
83
// move the temp file back to the original file
83
84
// return true iff it succeeded
85
+ //
84
86
85
87
let tempFile = inputFile . filename + ".tmp" ;
86
- let original_content = inputFile . content ;
87
- await workspace . writeText ( tempFile , inputFile . content ) ;
88
- await workspace . writeText ( inputFile . filename , code ) ;
88
+ let old_code = inputFile . content ;
89
+ await workspace . writeText ( tempFile , old_code ) ;
90
+ await workspace . writeText ( inputFile . filename , new_code ) ;
89
91
let result = await host . exec ( `cmd /k "C:\Program\ Files/Microsoft\ Visual\ Studio/2022/Enterprise/Common7/Tools/VsDevCmd.bat" -arch=x64 & ninja` , { cwd : "build" } ) ;
90
-
91
- // await fs.delete(tempFile);
92
- if ( result . exitCode !== 0 ) {
93
- await workspace . writeText ( inputFile . filename , original_content ) ;
94
- console . log ( result . stderr ) ;
95
- return false ;
92
+ await workspace . writeText ( inputFile . filename , old_code ) ;
93
+ if ( result . exitCode == 0 ) {
94
+ await workspace . writeText ( tempFile , new_code ) ;
95
+ return true ;
96
96
}
97
- return true ;
97
+ console . log ( result . stderr ) ;
98
+ return false ;
99
+
98
100
}
99
101
100
- export async function mergeCompileFunction ( inputFile : WorkspaceFile , code : string , funs : { code : string , name : string } [ ] , new_code_input : string ) {
102
+ export async function mergeCompileFunction ( inputFile : WorkspaceFile , code : string , funs : { code : string , name : string } [ ] , new_code_input : string ) {
101
103
let match_new_code = new_code_input . match ( / ` ` ` c p p ( [ \s \S ] * ?) ` ` ` / ) ;
102
104
if ( ! match_new_code ) {
103
105
console . log ( "Invalid new code" ) ;
@@ -110,8 +112,10 @@ export async function mergeCompileFunction(inputFile : WorkspaceFile, code : str
110
112
111
113
if ( ! fun ) {
112
114
console . log ( `Function name '${ name } ' not found` ) ;
113
- for ( const fun of funs )
115
+ console . log ( "Available functions: " ) ;
116
+ for ( const fun of funs )
114
117
console . log ( "'" + fun . name + "'" ) ;
118
+ console . log ( new_code ) ;
115
119
return code ;
116
120
}
117
121
console . log ( "Updated function: " + name ) ;
@@ -122,15 +126,15 @@ export async function mergeCompileFunction(inputFile : WorkspaceFile, code : str
122
126
}
123
127
let canCompile = await canCompileCode ( inputFile , modified_code ) ;
124
128
console . log ( "Can compile: " + canCompile ) ;
125
- if ( canCompile )
129
+ if ( canCompile )
126
130
return modified_code ;
127
131
return code ;
128
132
}
129
133
130
134
export async function mergeFunctionsFromList ( inputCode : string , funs : { code : string , name : string } [ ] , modifiedFunctionList : string [ ] ) {
131
135
let code = inputCode ;
132
- for ( const new_code of modifiedFunctionList )
133
- code = await mergeModifiedFunction ( code , funs , new_code ) ;
136
+ for ( const new_code of modifiedFunctionList )
137
+ code = await mergeModifiedFunction ( code , funs , new_code ) ;
134
138
return code ;
135
139
}
136
140
@@ -140,7 +144,7 @@ export async function mergeFunctions(inputFile: WorkspaceFile) {
140
144
return mergeFunctionsFromList ( inputFile . content , funs , modifiedFunctionList ) ;
141
145
}
142
146
143
- export async function invokeLLMOpt ( code : string ) {
147
+ export async function invokeLLMOpt ( code : string ) {
144
148
const answer = await runPrompt (
145
149
( _ ) => {
146
150
_ . def ( "CODE" , code ) ;
0 commit comments