diff --git a/README.md b/README.md index aea4823..2c87bcc 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A lightweight turing-incomplete assembly language for STARK proofs. Designed to Each line of a circuitvm `asm` file should contain an opcode, followed by registers to operate on. Each argument should be separated by exactly 1 space. Numbers may be prefixed by `0x` for hex, or written normally for decimal. -Lines starting with `#` or containing only whitespace are ignored. +Lines starting with `;` or containing only whitespace are ignored. ## Opcodes diff --git a/src/compiler.mjs b/src/compiler.mjs index 8587039..b5fab2a 100644 --- a/src/compiler.mjs +++ b/src/compiler.mjs @@ -104,14 +104,15 @@ export function compile(asm) { const steps = asm .split('\n') .filter(line => { - if (line.startsWith('#')) return false + if (line.trim().startsWith(';')) return false if (line.trim().length === 0) return false return true }) .map(line => line.trim()) .map(line => line.split(' ')) .map((operation, i) => { - const [ op, ...args ] = operation + const commentIndex = operation.indexOf(';') + const [ op, ...args ] = commentIndex >= 0 ? operation.slice(0, commentIndex) : operation if (!validOperations[op]) { throw new Error(`Invalid op "${op}"`) } diff --git a/test/example1.asm b/test/example1.asm index 804e01b..3da4526 100644 --- a/test/example1.asm +++ b/test/example1.asm @@ -1,16 +1,16 @@ -# a simple repeated squaring program +; a simple repeated squaring program set 0x0 100 -# calculate 100^4 +; calculate 100^4 mul 0x1 0x0 0x0 mul 0x1 0x0 0x1 mul 0x1 0x0 0x1 -# make a public signal and assert its expected value +; make a public signal and assert its expected value out 0x1 100000000 -# now calculate 200^4 +; now calculate 200^4 set 0x0 200 mul 0x1 0x0 0x0 mul 0x1 0x0 0x1 mul 0x1 0x0 0x1 -# and output +; and output out 0x1 1600000000 -# registers can be reused after an output is marked +; registers can be reused after an output is marked