From 0ccbc4586ab156fb17c5faa93d719764d259e5a8 Mon Sep 17 00:00:00 2001 From: Jonathan Cubides Date: Wed, 22 Feb 2023 17:28:33 +0100 Subject: [PATCH] Bump up version to 0.1.30 --- package.json | 6 +- src/config.ts | 4 +- src/extension.ts | 2 +- src/vampir/commands.ts | 161 --------------------------------------- src/vampir/tasks.ts | 169 +++++++++++++++++++++++++++++++++++++++++ test/range.pir | 1 + test/vampir.json | 1 + 7 files changed, 177 insertions(+), 167 deletions(-) delete mode 100644 src/vampir/commands.ts create mode 100644 src/vampir/tasks.ts create mode 100644 test/vampir.json diff --git a/package.json b/package.json index 94ecfa6..fb31957 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "juvix-mode", - "version": "0.1.29", + "version": "0.1.30", "license": "GPL-3.0", "description": "Juvix Mode for VSCode", "displayName": "Juvix", @@ -590,9 +590,9 @@ }, "juvix-mode.vampirBinName": { "type": "string", - "default": "vampir", + "default": "vamp-ir", "scope": "machine-overridable", - "description": "Name of the executable of VampIR. (e.g. vampir)" + "description": "Name of the executable of VampIR. (e.g. vamp-ir)" }, "juvix-mode.vampirBinPath": { "type": "string", diff --git a/src/config.ts b/src/config.ts index 52d99f5..35fe5df 100644 --- a/src/config.ts +++ b/src/config.ts @@ -26,8 +26,8 @@ export class JuvixConfig { } // geb settings - readonly vampirBinaryName = new VsCodeSetting('juvix-mode.vampirName', { - serializer: serializerWithDefault('vampir'), + readonly vampirBinaryName = new VsCodeSetting('juvix-mode.vampirBinName', { + serializer: serializerWithDefault('vamp-ir'), }); readonly vampirBinaryPath = new VsCodeSetting('juvix-mode.vampirBinPath', { serializer: serializerWithDefault(''), diff --git a/src/extension.ts b/src/extension.ts index 8470d8f..a98eb82 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -15,7 +15,7 @@ import * as judoc from './judoc'; import * as dev from './dev'; import * as check from './check'; import * as formatter from './formatter'; -import * as vampir from './vampir/commands'; +import * as vampir from './vampir/tasks'; export async function activate(context: vscode.ExtensionContext) { debugChannel.clear(); diff --git a/src/vampir/commands.ts b/src/vampir/commands.ts deleted file mode 100644 index a16564f..0000000 --- a/src/vampir/commands.ts +++ /dev/null @@ -1,161 +0,0 @@ -/*--------------------------------------------------------- - * Copyright (C) Microsoft Corporation. All rights reserved. - *--------------------------------------------------------*/ -'use strict'; - -import * as vscode from 'vscode'; -import { debugChannel } from './../utils/debug'; -import { isVampIRFile } from './../utils/base'; -import { JuvixConfig } from './../config'; -import * as fs from 'fs'; - -export function activate(context: vscode.ExtensionContext) { - debugChannel.clear(); - debugChannel.info('Loading VampIR support!'); - const config = new JuvixConfig(); - - context.subscriptions.push( - vscode.commands.registerCommand('juvix-mode.vampir-setup', () => { - debugChannel.info('VampIR command invoked!'); - - const setupCall = [ - config.getVampirExec(), - 'setup', - '--unchecked', - '-o', - 'params.pp', - ].join(' '); - - debugChannel.appendLine(setupCall); - - const { spawnSync } = require('child_process'); - const ls = spawnSync(setupCall, { - shell: true, - encoding: 'utf8', - }); - - debugChannel.appendLine(ls.stdout); - - if (ls.status == 0) { - const stdout = ls.stdout; - debugChannel.appendLine(stdout); - } else { - const errMsg: string = ls.stderr.toString(); - throw new Error(errMsg); - } - }) - ); - - context.subscriptions.push( - vscode.commands.registerCommand('juvix-mode.vampir-compile', () => { - debugChannel.info('VampIR command invoked!'); - - const aEditor = vscode.window.activeTextEditor; - let vampirFile = undefined; - if (aEditor && aEditor.document) { - const currentDocument = aEditor.document; - if (isVampIRFile(currentDocument)) vampirFile = currentDocument.uri; - } - // vamp-ir compile -u params.pp -s tests/range.pir -o circuit.plonk - const compileCall = [ - config.getVampirExec(), - 'compile', - '-u', - 'params.pp', - vampirFile, - '-o', - 'circuit.plonk', - ].join(' '); - - debugChannel.appendLine(compileCall); - - const { spawnSync } = require('child_process'); - const ls = spawnSync(compileCall, { - shell: true, - encoding: 'utf8', - }); - - debugChannel.appendLine(ls.stdout); - - if (ls.status == 0) { - const stdout = ls.stdout; - debugChannel.appendLine(stdout); - } else { - const errMsg: string = ls.stderr.toString(); - throw new Error(errMsg); - } - }) - ); - context.subscriptions.push( - vscode.commands.registerCommand('juvix-mode.vampir-prove', () => { - debugChannel.info('VampIR command invoked!'); - - const proveCall = [ - config.getVampirExec(), - 'prove', - '-u', - 'params.pp', - '-c', - 'circuit.plonk', - '-o', - 'proof.plonk', - '-i', - 'vampir.json', - ].join(' '); - - debugChannel.appendLine(proveCall); - - const { spawnSync } = require('child_process'); - const ls = spawnSync(proveCall, { - shell: true, - encoding: 'utf8', - }); - - debugChannel.appendLine(ls.stdout); - - if (ls.status == 0) { - const stdout = ls.stdout; - debugChannel.appendLine(stdout); - } else { - const errMsg: string = ls.stderr.toString(); - throw new Error(errMsg); - } - }) - ); - - context.subscriptions.push( - vscode.commands.registerCommand('juvix-mode.vampir-verify', () => { - debugChannel.info('VampIR command invoked!'); - // vamp-ir verify -u params.pp -c circuit.plonk -p proof.plonk - - const verifyCall = [ - config.getVampirExec(), - 'verify', - '-u', - 'params.pp', - '-c', - 'circuit.plonk', - '-p', - 'proof.plonk', - ].join(' '); - - debugChannel.appendLine(verifyCall); - - const { spawnSync } = require('child_process'); - const ls = spawnSync(verifyCall, { - shell: true, - encoding: 'utf8', - }); - - debugChannel.appendLine(ls.stdout); - - if (ls.status == 0) { - const stdout = ls.stdout; - debugChannel.appendLine(stdout); - } else { - const errMsg: string = ls.stderr.toString(); - throw new Error(errMsg); - } - }) - ); -} diff --git a/src/vampir/tasks.ts b/src/vampir/tasks.ts new file mode 100644 index 0000000..992e392 --- /dev/null +++ b/src/vampir/tasks.ts @@ -0,0 +1,169 @@ +/*--------------------------------------------------------- + * Copyright (C) Microsoft Corporation. All rights reserved. + *--------------------------------------------------------*/ +'use strict'; + +import * as vscode from 'vscode'; +import { debugChannel } from '../utils/debug'; +import { JuvixConfig } from '../config'; + +export const TASK_TYPE = 'VampIR'; + +export async function activate(context: vscode.ExtensionContext) { + if (vscode.workspace.workspaceFolders === undefined) { + const msg = 'VampIR extension requires at least one workspace open.\n'; + vscode.window.showErrorMessage(msg); + debugChannel.error(msg); + return; + } + + const provider = new VampIRProvider(); + const vampIRTasks: Promise = provider.provideTasks(); + context.subscriptions.push( + vscode.tasks.registerTaskProvider(TASK_TYPE, provider) + ); + + vampIRTasks + .then(tasks => { + for (const task of tasks) { + const cmdName = task.name; + const qualifiedCmdName = 'juvix-mode.vampir-' + cmdName; + const cmd = vscode.commands.registerTextEditorCommand( + qualifiedCmdName, + () => { + const ex = vscode.tasks.executeTask(task); + ex.then((v: vscode.TaskExecution) => { + debugChannel.info('Task "' + cmdName + '" executed'); + v.terminate(); + return true; + }); + debugChannel.info('VampIR Task "' + cmdName + '" executed'); + return false; + } + ); + context.subscriptions.push(cmd); + debugChannel.info('[!] VampIR "' + cmdName + '" command registered'); + } + }) + .catch(err => { + debugChannel.error('VampIR Task provider error: ' + err); + }); +} + +export interface VampIRDefinition extends vscode.TaskDefinition { + command?: string; + args?: string[]; +} + +export class VampIRProvider implements vscode.TaskProvider { + async provideTasks(): Promise { + const config = new JuvixConfig(); + + const defs = [ + { + command: 'setup', + args: ['--unchecked', '-o', 'params.pp'], + group: vscode.TaskGroup.Build, + reveal: vscode.TaskRevealKind.Always, + }, + { + command: 'compile', + args: [ + '-u', + 'params.pp', + '--unchecked', + '-s', + '${file}', + '-o', + '${file}.plonk', + ], + group: vscode.TaskGroup.Build, + reveal: vscode.TaskRevealKind.Always, + }, + { + // prove -u params.pp --unchecked -c range.plonk -o range.proof + command: 'prove', + args: [ + '-u', + 'params.pp', + '--unchecked', + '-c', + '${file}.plonk', + '-o', + '${file}.proof', + ], + group: vscode.TaskGroup.Build, + reveal: vscode.TaskRevealKind.Always, + }, + { + //vamp-ir verify -u params.pp --unchecked -c range.plonk -p range.proof + command: 'verify', + args: [ + '-u', + 'params.pp', + '--unchecked', + '-c', + '${file}.plonk', + '-p', + '${file}.proof', + ], + group: vscode.TaskGroup.Build, + reveal: vscode.TaskRevealKind.Always, + }, + ]; + + const tasks: vscode.Task[] = []; + + for (const def of defs) { + const vscodeTask = await VampIR( + { type: TASK_TYPE, command: def.command }, // definition + def.command, // name + [def.command].concat(def.args ?? []) // args + ); + vscodeTask.group = def.group; + vscodeTask.problemMatchers = ['$rusterror']; + vscodeTask.presentationOptions = { + reveal: def.reveal, + showReuseMessage: false, + panel: vscode.TaskPanelKind.Shared, + focus: false, + echo: false, + clear: true, + }; + vscodeTask.runOptions = { + reevaluateOnRerun: true, + }; + tasks.push(vscodeTask); + } + return tasks; + } + + async resolveTask(task: any): Promise { + const definition = task.definition as VampIRDefinition; + if (definition.type === TASK_TYPE && definition.command) { + const args = [definition.command].concat(definition.args ?? []); + return await VampIR(definition, task.name, args); + } + debugChannel.warn('resolveTask: fail to resolve', task); + return undefined; + } +} + +export async function VampIR( + definition: VampIRDefinition, + name: string, + args: string[] +): Promise { + let input = args.join(' ').trim(); + const config = new JuvixConfig(); + const VampirExec = config.getVampirExec(); + let exec = new vscode.ShellExecution(VampirExec + ` ${input}`); + return new vscode.Task( + definition, + vscode.TaskScope.Global, + name, + TASK_TYPE, + exec, + ['$juvixerror'] + ); +} diff --git a/test/range.pir b/test/range.pir index ed96d53..33f7250 100644 --- a/test/range.pir +++ b/test/range.pir @@ -4,6 +4,7 @@ vamp-ir compile -u params.pp -s tests/range.pir -o circuit.plonk vamp-ir prove -u params.pp -c circuit.plonk -o proof.plonk vamp-ir verify -u params.pp -c circuit.plonk -p proof.plonk + */ pub x; diff --git a/test/vampir.json b/test/vampir.json new file mode 100644 index 0000000..0b75431 --- /dev/null +++ b/test/vampir.json @@ -0,0 +1 @@ +{ "x": "90" }