Skip to content

Investigate compilation of 'cashscript snippets' to CashASM #256

Open
@mr-zwets

Description

@mr-zwets

@jimtendo started a convestion on telegram (https://t.me/bch_compilers/7955) to ask

Might it be feasible in future to have some kind of compileScript function that allows CashScript to compile a short segment of CashScript into CashASM?
Something like:

// First arg is the script
// Second arg is the named values and their type
compileScript('a + b', {
 a: 'int',
 b: 'int',
})
// outputs:
// <a> <b> OP_ADD

Rosco replied (https://t.me/bch_compilers/8000) that we could try to support the following:

compileScript(`function x(int a, int b) { return a + b }`);

// or

const requireLockscriptP2PKH = compileScript(`
function checkLockingBytecode(bytes lockingBytecode) {
  require(lockingBytecode.length == 25);
  require(lockingBytecode.split(3)[0] == 0x76a914);
  require(lockingBytecode.split(23)[1] == 0x88ac);
}`);

That way we skip the contract overhead, but keep the function definition that has parameter data

Creating self-contained "functions" is something that is on the roadmap (although specifics are yet to be defined), but when we implement that, we could try to ensure that they could be compiled by themselves so they could be used for use cases like yours

adding a "target" for CashASM (besides "regular" hex bytecode / asm) should be doable as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cashc-compilerRelates to the cashc compilerenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions