Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/Editor/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ PUSH1 32
PUSH1 0
RETURN`,
],
Huff: [
`#define macro MAIN() = takes (0) returns (0) {
0x5361772d6d6f6e2026204e6174616c6965 0x00 mstore // Store a value in memory.
0x11 0x0f return // Return 17 bytes starting from memory pointer 15.
}`,
],
}

export default examples
9 changes: 9 additions & 0 deletions components/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { encode, decode } from '@kunigi/string-compression'
import cn from 'classnames'
import copy from 'copy-to-clipboard'
import { BN } from 'ethereumjs-util'
import compileHuff from 'huffc'
import { useRouter } from 'next/router'
import Select, { OnChangeValue } from 'react-select'
import SCEditor from 'react-simple-code-editor'
Expand Down Expand Up @@ -282,6 +283,14 @@ const Editor = ({ readOnly = false }: Props) => {
}
loadInstructions(code)
startExecution(code, _callValue, _callData)
} else if (codeType === CodeType.Huff) {
const { runtimeBytecode: bytecode } = compileHuff({
filePath: '',
generateAbi: true,
content: code,
})
loadInstructions(bytecode)
startExecution(bytecode, _callValue, _callData)
} else {
setIsCompiling(true)
log('Starting compilation...')
Expand Down
1 change: 1 addition & 0 deletions components/Editor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export enum CodeType {
Solidity = 'Solidity',
Bytecode = 'Bytecode',
Mnemonic = 'Mnemonic',
Huff = 'Huff',
}

export enum ValueUnit {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"gray-matter": "^4.0.3",
"highlight.js": "^11.3.1",
"highlightjs-solidity": "^2.0.1",
"huffc": "Saw-mon-and-Natalie/huffc.git#fileless-parser",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anything, why not point to the original repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original repo only compiles files and not the content as strings. It also misses declaration files for typescript.

Once those has been added/modified in the original repo, we can change this to huffc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created a PR for huffc to include the required changes:
feat: Allow parsing/compiling of content only data ...

Once that PR is reviewed and merged, we can update this dependency.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great thanks :-)

"kbar": "^0.1.0-beta.16",
"lodash.debounce": "^4.0.8",
"next": "12",
Expand Down
3 changes: 3 additions & 0 deletions util/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const reFullHex = /^(0x|0X)([0-9a-fA-F][0-9a-fA-F])+$/
hljsDefineSolidity(hljs)
hljs.registerLanguage('mnemonic', hljsDefineMnemonic)

// Add Huff to Highlight
hljs.registerLanguage('huff', hljsDefineMnemonic)

/**
* Checks whether text is empty.
*/
Expand Down
Loading