Compare commits
1 Commits
feat/initi
...
feat/asc-c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78c241f68a |
@@ -210,7 +210,12 @@ const HooksEditor = () => {
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
|
||||
experimentalDecorators: true
|
||||
})
|
||||
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
|
||||
diagnosticCodesToIgnore: [1206]
|
||||
})
|
||||
monaco.languages.typescript.typescriptDefaults.addExtraLib(
|
||||
asc.definitionFiles.assembly,
|
||||
'assemblyscript/std/assembly/index.d.ts'
|
||||
@@ -224,6 +229,7 @@ const HooksEditor = () => {
|
||||
aliases: ['C', 'c', 'H', 'h'],
|
||||
mimetypes: ['text/plain']
|
||||
})
|
||||
|
||||
MonacoServices.install(monaco)
|
||||
const webSocket = createWebSocket(
|
||||
process.env.NEXT_PUBLIC_LANGUAGE_SERVER_API_ENDPOINT || ''
|
||||
|
||||
BIN
public/cleaner.wasm
Executable file
BIN
public/cleaner.wasm
Executable file
Binary file not shown.
@@ -6,6 +6,8 @@ import { saveFile } from './saveFile'
|
||||
import { decodeBinary } from '../../utils/decodeBinary'
|
||||
import { ref } from 'valtio'
|
||||
|
||||
import Cleaner from '../../utils/cleaner/cleaner'
|
||||
|
||||
/* compileCode sends the code of the active file to compile endpoint
|
||||
* If all goes well you will get base64 encoded wasm file back with
|
||||
* some extra logging information if we can provide it. This function
|
||||
@@ -19,7 +21,7 @@ export const compileCode = async (activeId: number) => {
|
||||
if (!process.env.NEXT_PUBLIC_COMPILE_API_ENDPOINT) {
|
||||
throw Error('Missing env!')
|
||||
}
|
||||
// Bail out if we're already compiling
|
||||
// Bail out if we're already compiling
|
||||
if (state.compiling) {
|
||||
// if compiling is ongoing return // TODO Inform user about it.
|
||||
return
|
||||
@@ -44,26 +46,54 @@ export const compileCode = async (activeId: number) => {
|
||||
state.files[activeId].name,
|
||||
'--textFile',
|
||||
'-o',
|
||||
state.files[activeId].name,
|
||||
`${state.files[activeId].name}.wasm`,
|
||||
'--runtime',
|
||||
'minimal',
|
||||
'-O3'
|
||||
'stub',
|
||||
'-O3',
|
||||
'--disable',
|
||||
'bulk-memory'
|
||||
],
|
||||
{
|
||||
readFile: (name, baseDir) => {
|
||||
console.log('--> ', name)
|
||||
const currentFile = state.files.find(file => file.name === name)
|
||||
if (currentFile) {
|
||||
return currentFile.content
|
||||
}
|
||||
return null
|
||||
},
|
||||
writeFile: (name, data, baseDir) => {
|
||||
console.log(name)
|
||||
const curr = state.files.find(file => file.name === name)
|
||||
writeFile: async (name, data, baseDir) => {
|
||||
const curr = state.files.find(file => file.name === name.replace('.wasm', ''))
|
||||
if (curr) {
|
||||
curr.compiledContent = ref(data)
|
||||
const cleaner = await Cleaner({
|
||||
locateFile: (file: string) => {
|
||||
return `/${file}`
|
||||
}
|
||||
})
|
||||
|
||||
cleaner.FS.mkdir('compiled')
|
||||
cleaner.FS.createDataFile('/compiled', `${curr?.name}.wasm`, data, true, true)
|
||||
await cleaner.callMain([`/compiled/${curr?.name}.wasm`])
|
||||
const newFileUArr = cleaner.FS.readFile(`/compiled/${curr?.name}.wasm`) as Uint8Array
|
||||
// lets remove the file from the file system
|
||||
cleaner.FS.unlink(`/compiled/${curr.name}.wasm`)
|
||||
// lets remove the directory
|
||||
cleaner.FS.rmdir('compiled')
|
||||
|
||||
curr.compiledContent = ref(newFileUArr)
|
||||
}
|
||||
|
||||
const ww = (await import('wabt')).default()
|
||||
if (curr?.compiledContent) {
|
||||
if (curr.compiledContent instanceof Uint8Array) {
|
||||
const myModule = ww.readWasm(curr.compiledContent, {
|
||||
readDebugNames: true
|
||||
})
|
||||
myModule.applyNames()
|
||||
const compiledWat = myModule.toText({ foldExprs: false, inlineExport: false })
|
||||
curr.compiledWatContent = compiledWat
|
||||
}
|
||||
}
|
||||
toast.success('Compiled successfully!', { position: 'bottom-center' })
|
||||
},
|
||||
listFiles: (dirname, baseDir) => {
|
||||
console.log('listFiles: ' + dirname + ', baseDir=' + baseDir)
|
||||
@@ -90,9 +120,8 @@ export const compileCode = async (activeId: number) => {
|
||||
return
|
||||
}
|
||||
if (res.stdout) {
|
||||
const wat = res.stdout.toString()
|
||||
state.files[activeId].lastCompiled = new Date()
|
||||
state.files[activeId].compiledWatContent = wat
|
||||
console.log(res.stdout.toString())
|
||||
state.files[activeId].compiledValueSnapshot = state.files[activeId].content
|
||||
state.logs.push({
|
||||
type: 'success',
|
||||
@@ -101,6 +130,19 @@ export const compileCode = async (activeId: number) => {
|
||||
linkText: 'Go to deploy'
|
||||
})
|
||||
}
|
||||
// if (res.stdout) {
|
||||
// const wat = res.stdout.toString()
|
||||
// state.files[activeId].lastCompiled = new Date()
|
||||
// state.files[activeId].compiledWatContent = wat
|
||||
// state.files[activeId].compiledValueSnapshot = state.files[activeId].content
|
||||
// state.logs.push({
|
||||
// type: 'success',
|
||||
// message: `File ${state.files?.[activeId]?.name} compiled successfully. Ready to deploy.`,
|
||||
// link: Router.asPath.replace('develop', 'deploy'),
|
||||
// linkText: 'Go to deploy'
|
||||
// })
|
||||
// }
|
||||
console.log('nääää')
|
||||
state.compiling = false
|
||||
return
|
||||
}
|
||||
|
||||
4995
utils/cleaner/cleaner.js
Normal file
4995
utils/cleaner/cleaner.js
Normal file
File diff suppressed because it is too large
Load Diff
BIN
utils/cleaner/cleaner.wasm
Executable file
BIN
utils/cleaner/cleaner.wasm
Executable file
Binary file not shown.
Reference in New Issue
Block a user