|
|
|
@ -5,7 +5,8 @@ const textDecoder = new TextDecoder()
|
|
|
|
|
const daySelector = document.querySelector('.selector select')
|
|
|
|
|
const output = document.querySelector('.output')
|
|
|
|
|
const inputTextArea = document.querySelector('.ui textarea.input')
|
|
|
|
|
const outputTextArea = document.querySelector('.ui textarea.output')
|
|
|
|
|
const outputTextArea1 = document.querySelector('.ui textarea.output1')
|
|
|
|
|
const outputTextArea2 = document.querySelector('.ui textarea.output2')
|
|
|
|
|
const runButton = document.querySelector('.ui button')
|
|
|
|
|
|
|
|
|
|
async function getDayList() {
|
|
|
|
@ -72,11 +73,11 @@ async function loadDay(dayNum) {
|
|
|
|
|
output.innerText = 'Loaded day ' + dayNum
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function runLoaded() {
|
|
|
|
|
const { run, memory } = wasmInstance.exports;
|
|
|
|
|
function runLoaded(funcName, inputTextField, outputTextField) {
|
|
|
|
|
const { memory } = wasmInstance.exports;
|
|
|
|
|
const wasmBuffer = memory.buffer;
|
|
|
|
|
|
|
|
|
|
const inputBuffer = textEncoder.encode(inputTextArea.value)
|
|
|
|
|
const inputBuffer = textEncoder.encode(inputTextField.value)
|
|
|
|
|
|
|
|
|
|
// Set length and file contents
|
|
|
|
|
const inputLength = inputBuffer.length
|
|
|
|
@ -88,8 +89,8 @@ function runLoaded() {
|
|
|
|
|
inputSmallArray.set(fileInputNums, 4)
|
|
|
|
|
|
|
|
|
|
// run the wasm
|
|
|
|
|
outputTextArea.value = ""
|
|
|
|
|
const outputLocation = run()
|
|
|
|
|
outputTextField.value = ""
|
|
|
|
|
const outputLocation = wasmInstance.exports[funcName]()
|
|
|
|
|
|
|
|
|
|
// Read the output
|
|
|
|
|
const outputBuffer = wasmBuffer.slice(outputLocation)
|
|
|
|
@ -99,12 +100,13 @@ function runLoaded() {
|
|
|
|
|
const outputLength = outputLargeArray[0]
|
|
|
|
|
const outputBytes = outputSmallArray.slice(4, 4 + outputLength)
|
|
|
|
|
const outputText = textDecoder.decode(outputBytes)
|
|
|
|
|
outputTextArea.value = outputText
|
|
|
|
|
outputTextField.value = outputText
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
daySelector.value = ""
|
|
|
|
|
inputTextArea.value = ""
|
|
|
|
|
outputTextArea.value = ""
|
|
|
|
|
outputTextArea1.value = ""
|
|
|
|
|
outputTextArea2.value = ""
|
|
|
|
|
|
|
|
|
|
getDayList().then(() => {
|
|
|
|
|
daySelector.addEventListener('change', ev => {
|
|
|
|
@ -114,5 +116,6 @@ getDayList().then(() => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runButton.addEventListener('click', ev => {
|
|
|
|
|
runLoaded()
|
|
|
|
|
runLoaded('part1', inputTextArea, outputTextArea1)
|
|
|
|
|
runLoaded('part2', inputTextArea, outputTextArea2)
|
|
|
|
|
})
|
|
|
|
|