Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/interpreter returns via events #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

TsBauer
Copy link
Member

@TsBauer TsBauer commented Dec 1, 2022

This PR contains changes which mostly pave the way for equal code consumption of the interpreter as well as the exec loop.

  • Interpreter emits exec results
  • Interpreter optionally emits exec memory
  • Interpreter receives calldata as dedicated params
  • Add interpreter felt code example for multiplication
  • Interpreter prepares felt code

@TsBauer TsBauer added the enhancement New feature or request label Dec 1, 2022
@TsBauer TsBauer requested a review from marsmee December 1, 2022 13:31
@TsBauer TsBauer self-assigned this Dec 1, 2022
Comment on lines +16 to +24
func print{output_ptr: felt*}(felt_code_len: felt, felt_code: felt*) {
if (felt_code_len == 0) {
return ();
}

serialize_word(felt_code[0]);

return print(felt_code_len - 1, felt_code + 1);
}
Copy link

Choose a reason for hiding this comment

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

same as in printMul.cairo
maybe a common printArray function would be better?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree. The use case of those ˋprint{xyz}.cairoˋ is anyways awkward, because it's just a helper for the deployment and not part of any smart contract. I solved this in a different branch where I refactored the bootstrapper.

Comment on lines +5 to +12
func add_row(_table_len: felt, _table: felt*, _row_len: felt, _row: felt*) -> felt {
assert _table[_table_len] = _row_len;
let _table_len = _table_len + 1;

memcpy(_table + _table_len, _row, _row_len);
let _table_len = _table_len + _row_len;

return _table_len;
Copy link

Choose a reason for hiding this comment

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

use case for this function is kind of confusing to me atm.
it actually merges two felt arrays using memcpy but i see two other options here:

  1. using another struct to aggregate data
  2. use recursion instead of memcpy
    add_row(_table_len + 1, _table + 1, _row_len - 1, _row + 1)

moreover, the name could rather be add_rows or something like append_felts.

Comment on lines 31 to 45
tempvar instruction0 = Instruction(
primitive=Primitive(starkshell_hash, mul_keyword),
input1=Calldata,
input2=NULLvar,
output=mulvar,
);

tempvar instruction1 = Instruction(
primitive=Primitive(starkshell_hash, return_keyword),
input1=mulvar,
input2=NULLvar,
output=NULLvar,
);

tempvar program = new (instruction0, instruction1);
Copy link

Choose a reason for hiding this comment

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

is a tuple the way to go here? i'd expect an array of instructions instead a tuple (more flexible if there're more than two):

    let (local instructions: Instruction*) = alloc();
    assert [instructions + 0] = Instruction( ... );
    assert [instructions + 1] = Instruction( ... );
    const INSTRUCTIONS_LEN = 2;

Comment on lines +80 to +90
let (local table: felt*) = alloc();
let (local row: felt*) = alloc();

assert table[0] = 0;

assert row[0] = 11;
assert row[1] = 12;
assert row[2] = 13;

local table_len = 1;
local row_len = 3;
Copy link

Choose a reason for hiding this comment

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

in general it might be better to reorder those commands to reduce the change mistakes like forgetting to update an array size.

  1. allocation
  2. appendages
  3. const LEN

Comment on lines +97 to +99
assert_eq(table[2], 11);
assert_eq(table[3], 12);
assert_eq(table[4], 13);
Copy link

Choose a reason for hiding this comment

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

assert_eq against the origin (row[x])? or using consts

_calldata_len=calldata_len,
_calldata=calldata,
);
%{ stop_prank() %}
Copy link

Choose a reason for hiding this comment

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

yes, please stop it 😬
the test gets way more complicated than the code we want to test with it. also it highly depends on the implementation and not only an interface.

@TsBauer TsBauer force-pushed the main branch 2 times, most recently from 0a620b2 to 599dced Compare April 14, 2023 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants