Compare commits
7 Commits
feat/flags
...
docs_updat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f868da636 | ||
|
|
5794aebe47 | ||
|
|
48daf1c5c8 | ||
|
|
a3365e4beb | ||
|
|
45d813cdad | ||
|
|
911416aa2f | ||
|
|
2d836af9ed |
@@ -64,7 +64,7 @@
|
|||||||
"valtio": "^1.2.5",
|
"valtio": "^1.2.5",
|
||||||
"vscode-languageserver": "^7.0.0",
|
"vscode-languageserver": "^7.0.0",
|
||||||
"vscode-uri": "^3.0.2",
|
"vscode-uri": "^3.0.2",
|
||||||
"wabt": "1.0.16",
|
"wabt": "^1.0.30",
|
||||||
"xrpl-accountlib": "^1.5.2",
|
"xrpl-accountlib": "^1.5.2",
|
||||||
"xrpl-client": "^1.9.4"
|
"xrpl-client": "^1.9.4"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ const Home: NextPage = () => {
|
|||||||
|
|
||||||
const activeFile = snap.files[snap.active] as IFile | undefined
|
const activeFile = snap.files[snap.active] as IFile | undefined
|
||||||
const activeFileExt = getFileExtention(activeFile?.name)
|
const activeFileExt = getFileExtention(activeFile?.name)
|
||||||
|
const canCompile = activeFileExt === 'c' || activeFileExt === 'wat'
|
||||||
return (
|
return (
|
||||||
<Split
|
<Split
|
||||||
direction="vertical"
|
direction="vertical"
|
||||||
@@ -162,7 +163,7 @@ const Home: NextPage = () => {
|
|||||||
>
|
>
|
||||||
<main style={{ display: 'flex', flex: 1, position: 'relative' }}>
|
<main style={{ display: 'flex', flex: 1, position: 'relative' }}>
|
||||||
<HooksEditor />
|
<HooksEditor />
|
||||||
{activeFileExt === 'c' && (
|
{canCompile && (
|
||||||
<Hotkeys
|
<Hotkeys
|
||||||
keyName="command+b,ctrl+b"
|
keyName="command+b,ctrl+b"
|
||||||
onKeyDown={() => !snap.compiling && snap.files.length && compileCode(snap.active)}
|
onKeyDown={() => !snap.compiling && snap.files.length && compileCode(snap.active)}
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ import { ref } from 'valtio'
|
|||||||
export const compileCode = async (activeId: number) => {
|
export const compileCode = async (activeId: number) => {
|
||||||
// Save the file to global state
|
// Save the file to global state
|
||||||
saveFile(false, activeId)
|
saveFile(false, activeId)
|
||||||
|
const file = state.files[activeId]
|
||||||
|
if (file.name.endsWith('.wat')) {
|
||||||
|
return compileWat(activeId)
|
||||||
|
}
|
||||||
|
|
||||||
if (!process.env.NEXT_PUBLIC_COMPILE_API_ENDPOINT) {
|
if (!process.env.NEXT_PUBLIC_COMPILE_API_ENDPOINT) {
|
||||||
throw Error('Missing env!')
|
throw Error('Missing env!')
|
||||||
}
|
}
|
||||||
@@ -26,7 +31,6 @@ export const compileCode = async (activeId: number) => {
|
|||||||
// Set loading state to true
|
// Set loading state to true
|
||||||
state.compiling = true
|
state.compiling = true
|
||||||
state.logs = []
|
state.logs = []
|
||||||
const file = state.files[activeId]
|
|
||||||
try {
|
try {
|
||||||
file.containsErrors = false
|
file.containsErrors = false
|
||||||
let res: Response
|
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
|
// Import wabt from and create human readable version of wasm file and
|
||||||
// put it into state
|
// put it into state
|
||||||
const ww = (await import('wabt')).default()
|
const ww = await (await import('wabt')).default()
|
||||||
const myModule = ww.readWasm(new Uint8Array(bufferData), {
|
const myModule = ww.readWasm(new Uint8Array(bufferData), {
|
||||||
readDebugNames: true
|
readDebugNames: true
|
||||||
})
|
})
|
||||||
@@ -122,3 +126,46 @@ export const compileCode = async (activeId: number) => {
|
|||||||
file.containsErrors = true
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ export const fetchFiles = async (gistId: string) => {
|
|||||||
// default priority is undefined == 0
|
// default priority is undefined == 0
|
||||||
const extPriority: Record<string, number> = {
|
const extPriority: Record<string, number> = {
|
||||||
c: 3,
|
c: 3,
|
||||||
|
wat: 3,
|
||||||
md: 2,
|
md: 2,
|
||||||
h: -1
|
h: -1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import hooksFloatManipPure from './md/hooks-float-manip-pure.md'
|
|||||||
import hooksFloatOnePure from './md/hooks-float-one-pure.md'
|
import hooksFloatOnePure from './md/hooks-float-one-pure.md'
|
||||||
import hooksFloatPure from './md/hooks-float-pure.md'
|
import hooksFloatPure from './md/hooks-float-pure.md'
|
||||||
import hooksGuardCalled from './md/hooks-guard-called.md'
|
import hooksGuardCalled from './md/hooks-guard-called.md'
|
||||||
|
import hooksGuardCallNonConst from './md/hooks-guard-call-non-const.md'
|
||||||
import hooksGuardInFor from './md/hooks-guard-in-for.md'
|
import hooksGuardInFor from './md/hooks-guard-in-for.md'
|
||||||
import hooksGuardInWhile from './md/hooks-guard-in-while.md'
|
import hooksGuardInWhile from './md/hooks-guard-in-while.md'
|
||||||
import hooksHashBufLen from './md/hooks-hash-buf-len.md'
|
import hooksHashBufLen from './md/hooks-hash-buf-len.md'
|
||||||
@@ -70,6 +71,7 @@ const docs: { [key: string]: string } = {
|
|||||||
'hooks-float-one-pure': hooksFloatOnePure,
|
'hooks-float-one-pure': hooksFloatOnePure,
|
||||||
'hooks-float-pure': hooksFloatPure,
|
'hooks-float-pure': hooksFloatPure,
|
||||||
'hooks-guard-called': hooksGuardCalled,
|
'hooks-guard-called': hooksGuardCalled,
|
||||||
|
'hooks-guard-call-non-const': hooksGuardCallNonConst,
|
||||||
'hooks-guard-in-for': hooksGuardInFor,
|
'hooks-guard-in-for': hooksGuardInFor,
|
||||||
'hooks-guard-in-while': hooksGuardInWhile,
|
'hooks-guard-in-while': hooksGuardInWhile,
|
||||||
'hooks-hash-buf-len': hooksHashBufLen,
|
'hooks-hash-buf-len': hooksHashBufLen,
|
||||||
|
|||||||
6
xrpl-hooks-docs/md/hooks-guard-call-non-const.md
Normal file
6
xrpl-hooks-docs/md/hooks-guard-call-non-const.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# hooks-guard-call-non-const
|
||||||
|
|
||||||
|
Only compile-time constants can be used as an argument in loop GUARD call. This check warns if a non compile-time constant is used.
|
||||||
|
It also checks whether a compile-time constant is used as a first argument of `_g()` call and whether it is a unique value. If not - it warns.
|
||||||
|
|
||||||
|
[Read more](https://xrpl-hooks.readme.io/v2.0/docs/loops-and-guarding)
|
||||||
@@ -1,14 +1,35 @@
|
|||||||
# hooks-guard-in-for
|
# hooks-guard-in-for
|
||||||
|
|
||||||
A guard is a marker that must be placed in your code at the top of each loop. Consider the following for-loop in C:
|
Consider the following for-loop in C:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
#define GUARD(maxiter) _g(__LINE__, (maxiter)+1)
|
#define GUARD(maxiter) _g(__LINE__, (maxiter)+1)
|
||||||
|
for (int i = 0; GUARD(3), i < 3; ++i)
|
||||||
for (int i = 0; GUARD(3), i < 3; ++i)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<BR/>
|
To satisfy the guard rule when using a for-loop in C guard should be
|
||||||
This is the only way to satisfy the guard rule when using a for-loop in C.
|
placed either in the condition part of the loop, or as a first call in loop body, e.g.
|
||||||
|
|
||||||
|
```c
|
||||||
|
for(int i = 0; i < 3; ++i) {
|
||||||
|
GUARD(3);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
In case of nested loops, the guard limit value should be
|
||||||
|
multiplied by a number of iterations in each loop, e.g.
|
||||||
|
|
||||||
|
```c
|
||||||
|
for(int i = 0; GUARD(3), i < 3; ++i) {
|
||||||
|
for (int j = 0; GUARD(17), j < 5; ++j)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
(most descendant loop iterations + 1) * (each parent loops iterations) - 1
|
||||||
|
```
|
||||||
|
|
||||||
|
This check will warn if the GUARD call is missing and also it will propose a GUARD value based on the for loop initial value,
|
||||||
|
the increment and loop condition.
|
||||||
|
|
||||||
[Read more](https://xrpl-hooks.readme.io/v2.0/docs/loops-and-guarding)
|
[Read more](https://xrpl-hooks.readme.io/v2.0/docs/loops-and-guarding)
|
||||||
|
|||||||
@@ -4765,10 +4765,10 @@ vscode-uri@^3.0.2:
|
|||||||
resolved "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.3.tgz"
|
resolved "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.3.tgz"
|
||||||
integrity sha512-EcswR2S8bpR7fD0YPeS7r2xXExrScVMxg4MedACaWHEtx9ftCF/qHG1xGkolzTPcEmjTavCQgbVzHUIdTMzFGA==
|
integrity sha512-EcswR2S8bpR7fD0YPeS7r2xXExrScVMxg4MedACaWHEtx9ftCF/qHG1xGkolzTPcEmjTavCQgbVzHUIdTMzFGA==
|
||||||
|
|
||||||
wabt@1.0.16:
|
wabt@^1.0.30:
|
||||||
version "1.0.16"
|
version "1.0.30"
|
||||||
resolved "https://registry.npmjs.org/wabt/-/wabt-1.0.16.tgz"
|
resolved "https://registry.yarnpkg.com/wabt/-/wabt-1.0.30.tgz#23cff6d38a05d0718e298fda371a70f0dff38ad7"
|
||||||
integrity sha512-aSQEAJfYkoZRY9Qt2/6hTM8yRX/Nc2R1bScET/4lppRqfUyzynB5HI+lK0u/hp8NbCVTAXg0iETviSS3zoufJw==
|
integrity sha512-qM1QnttJhjZ4vTSuXvder43yxgGhVffT/0wMc0SwYpboEW0/ENISpei/2kIDEMPrnNfTQ4GdvD7JIFV0IJPYog==
|
||||||
|
|
||||||
webidl-conversions@^3.0.0:
|
webidl-conversions@^3.0.0:
|
||||||
version "3.0.1"
|
version "3.0.1"
|
||||||
|
|||||||
Reference in New Issue
Block a user