2023-07-13 16:57:22 +10:00
|
|
|
import { Program } from '../lang/abstractSyntaxTreeTypes'
|
2023-06-22 16:43:33 +10:00
|
|
|
import { ProgramMemory, _executor } from '../lang/executor'
|
2023-08-24 15:34:51 -07:00
|
|
|
import {
|
|
|
|
EngineCommandManager,
|
|
|
|
EngineCommand,
|
|
|
|
} from '../lang/std/engineConnection'
|
|
|
|
import { SourceRange } from 'lang/executor'
|
2023-06-22 16:43:33 +10:00
|
|
|
|
2023-07-10 15:15:07 +10:00
|
|
|
class MockEngineCommandManager {
|
|
|
|
constructor(mockParams: {
|
|
|
|
setIsStreamReady: (isReady: boolean) => void
|
|
|
|
setMediaStream: (stream: MediaStream) => void
|
|
|
|
}) {}
|
|
|
|
startNewSession() {}
|
|
|
|
waitForAllCommands() {}
|
|
|
|
waitForReady = new Promise<void>((resolve) => resolve())
|
2023-08-24 15:34:51 -07:00
|
|
|
sendModelingCommand({
|
|
|
|
id,
|
|
|
|
range,
|
|
|
|
command,
|
|
|
|
}: {
|
|
|
|
id: string
|
|
|
|
range: SourceRange
|
|
|
|
command: EngineCommand
|
|
|
|
}): Promise<any> {
|
|
|
|
return Promise.resolve()
|
|
|
|
}
|
|
|
|
sendModelingCommandFromWasm(
|
|
|
|
id: string,
|
|
|
|
rangeStr: string,
|
|
|
|
commandStr: string
|
|
|
|
): Promise<any> {
|
|
|
|
if (id === undefined) {
|
|
|
|
throw new Error('id is undefined')
|
|
|
|
}
|
|
|
|
if (rangeStr === undefined) {
|
|
|
|
throw new Error('rangeStr is undefined')
|
|
|
|
}
|
|
|
|
if (commandStr === undefined) {
|
|
|
|
throw new Error('commandStr is undefined')
|
|
|
|
}
|
|
|
|
const command: EngineCommand = JSON.parse(commandStr)
|
|
|
|
const range: SourceRange = JSON.parse(rangeStr)
|
|
|
|
|
|
|
|
return this.sendModelingCommand({ id, range, command })
|
|
|
|
}
|
2023-07-10 15:15:07 +10:00
|
|
|
sendSceneCommand() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function enginelessExecutor(
|
|
|
|
ast: Program,
|
2023-09-12 18:10:27 -07:00
|
|
|
pm: ProgramMemory = { root: {}, return: null }
|
2023-07-10 15:15:07 +10:00
|
|
|
): Promise<ProgramMemory> {
|
|
|
|
const mockEngineCommandManager = new MockEngineCommandManager({
|
|
|
|
setIsStreamReady: () => {},
|
|
|
|
setMediaStream: () => {},
|
|
|
|
}) as any as EngineCommandManager
|
|
|
|
await mockEngineCommandManager.waitForReady
|
|
|
|
mockEngineCommandManager.startNewSession()
|
|
|
|
const programMemory = await _executor(ast, pm, mockEngineCommandManager)
|
|
|
|
await mockEngineCommandManager.waitForAllCommands()
|
|
|
|
return programMemory
|
|
|
|
}
|
|
|
|
|
2023-06-22 16:43:33 +10:00
|
|
|
export async function executor(
|
|
|
|
ast: Program,
|
2023-09-12 18:10:27 -07:00
|
|
|
pm: ProgramMemory = { root: {}, return: null }
|
2023-06-22 16:43:33 +10:00
|
|
|
): Promise<ProgramMemory> {
|
2023-06-23 14:19:15 +10:00
|
|
|
const engineCommandManager = new EngineCommandManager({
|
|
|
|
setIsStreamReady: () => {},
|
|
|
|
setMediaStream: () => {},
|
2023-08-09 20:49:10 +10:00
|
|
|
width: 100,
|
|
|
|
height: 100,
|
2023-06-23 14:19:15 +10:00
|
|
|
})
|
2023-07-10 15:15:07 +10:00
|
|
|
await engineCommandManager.waitForReady
|
2023-06-22 16:43:33 +10:00
|
|
|
engineCommandManager.startNewSession()
|
|
|
|
const programMemory = await _executor(ast, pm, engineCommandManager)
|
2023-09-14 13:49:59 +10:00
|
|
|
await engineCommandManager.waitForAllCommands(ast, programMemory)
|
2023-06-22 16:43:33 +10:00
|
|
|
return programMemory
|
|
|
|
}
|