Compare commits

...

3 Commits

Author SHA1 Message Date
muzam1l
a3365e4beb Increase wat file priority in sorting. 2022-12-07 15:02:09 +05:30
muzam1l
911416aa2f Compile wat files. 2022-12-07 13:31:59 +05:30
muzamil
2d836af9ed Merge pull request #276 from XRPLF/feat/flags-ui
Transaction flags UI.
2022-11-01 17:14:44 +05:30
5 changed files with 57 additions and 8 deletions

View File

@@ -64,7 +64,7 @@
"valtio": "^1.2.5",
"vscode-languageserver": "^7.0.0",
"vscode-uri": "^3.0.2",
"wabt": "1.0.16",
"wabt": "^1.0.30",
"xrpl-accountlib": "^1.5.2",
"xrpl-client": "^1.9.4"
},

View File

@@ -150,6 +150,7 @@ const Home: NextPage = () => {
const activeFile = snap.files[snap.active] as IFile | undefined
const activeFileExt = getFileExtention(activeFile?.name)
const canCompile = activeFileExt === 'c' || activeFileExt === 'wat'
return (
<Split
direction="vertical"
@@ -162,7 +163,7 @@ const Home: NextPage = () => {
>
<main style={{ display: 'flex', flex: 1, position: 'relative' }}>
<HooksEditor />
{activeFileExt === 'c' && (
{canCompile && (
<Hotkeys
keyName="command+b,ctrl+b"
onKeyDown={() => !snap.compiling && snap.files.length && compileCode(snap.active)}

View File

@@ -15,6 +15,11 @@ import { ref } from 'valtio'
export const compileCode = async (activeId: number) => {
// Save the file to global state
saveFile(false, activeId)
const file = state.files[activeId]
if (file.name.endsWith('.wat')) {
return compileWat(activeId)
}
if (!process.env.NEXT_PUBLIC_COMPILE_API_ENDPOINT) {
throw Error('Missing env!')
}
@@ -26,7 +31,6 @@ export const compileCode = async (activeId: number) => {
// Set loading state to true
state.compiling = true
state.logs = []
const file = state.files[activeId]
try {
file.containsErrors = false
let res: Response
@@ -72,7 +76,7 @@ export const compileCode = async (activeId: number) => {
// Import wabt from and create human readable version of wasm file and
// put it into state
const ww = (await import('wabt')).default()
const ww = await (await import('wabt')).default()
const myModule = ww.readWasm(new Uint8Array(bufferData), {
readDebugNames: true
})
@@ -122,3 +126,46 @@ export const compileCode = async (activeId: number) => {
file.containsErrors = true
}
}
export const compileWat = async (activeId: number) => {
if (state.compiling) return;
const file = state.files[activeId]
state.compiling = true
state.logs = []
try {
const wabt = await (await import('wabt')).default()
const module = wabt.parseWat(file.name, file.content);
module.resolveNames();
module.validate();
const { buffer } = module.toBinary({
log: false,
write_debug_names: true,
});
file.compiledContent = ref(buffer)
file.lastCompiled = new Date()
file.compiledValueSnapshot = file.content
file.compiledWatContent = file.content
toast.success('Compiled successfully!', { position: 'bottom-center' })
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'
})
} catch (err) {
console.log(err)
let message = "Error compiling WAT file!"
if (err instanceof Error) {
message = err.message
}
state.logs.push({
type: 'error',
message
})
toast.error(`Error occurred while compiling!`, { position: 'bottom-center' })
file.containsErrors = true
}
state.compiling = false
}

View File

@@ -61,6 +61,7 @@ export const fetchFiles = async (gistId: string) => {
// default priority is undefined == 0
const extPriority: Record<string, number> = {
c: 3,
wat: 3,
md: 2,
h: -1
}

View File

@@ -4765,10 +4765,10 @@ vscode-uri@^3.0.2:
resolved "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.3.tgz"
integrity sha512-EcswR2S8bpR7fD0YPeS7r2xXExrScVMxg4MedACaWHEtx9ftCF/qHG1xGkolzTPcEmjTavCQgbVzHUIdTMzFGA==
wabt@1.0.16:
version "1.0.16"
resolved "https://registry.npmjs.org/wabt/-/wabt-1.0.16.tgz"
integrity sha512-aSQEAJfYkoZRY9Qt2/6hTM8yRX/Nc2R1bScET/4lppRqfUyzynB5HI+lK0u/hp8NbCVTAXg0iETviSS3zoufJw==
wabt@^1.0.30:
version "1.0.30"
resolved "https://registry.yarnpkg.com/wabt/-/wabt-1.0.30.tgz#23cff6d38a05d0718e298fda371a70f0dff38ad7"
integrity sha512-qM1QnttJhjZ4vTSuXvder43yxgGhVffT/0wMc0SwYpboEW0/ENISpei/2kIDEMPrnNfTQ4GdvD7JIFV0IJPYog==
webidl-conversions@^3.0.0:
version "3.0.1"