Skip to content
Merged
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
1 change: 1 addition & 0 deletions tooling/noir_codegen/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ crs
lib

test/codegen
test/test_lib/export
4 changes: 2 additions & 2 deletions tooling/noir_codegen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ export const codegen = (programs: [string, CompiledCircuit][]): string => {
functions.push(codegenFunction(name, stripUnwantedFields(program), function_sig));
}

const structTypeDefinitions: string = codegenStructDefinitions(structTypeMap, primitiveTypeMap);

// Add the primitive Noir types that do not have a 1-1 mapping to TypeScript.
const primitiveTypeAliases: string[] = [];
for (const value of primitiveTypeMap.values()) {
primitiveTypeAliases.push(`export type ${value.aliasName} = ${value.tsType};`);
}

const structTypeDefinitions: string = codegenStructDefinitions(structTypeMap, primitiveTypeMap);

results = results.concat(...primitiveTypeAliases, '', structTypeDefinitions, ...functions);

return results.join('\n');
Expand Down
8 changes: 4 additions & 4 deletions tooling/noir_codegen/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { expect } from 'chai';
import { exported_function_foo, MyStruct, u64, ForeignCallHandler } from './codegen/index.js';

it('codegens a callable function', async () => {
const my_struct = { foo: true, bar: ['12345', '12345', '12345'] };
const my_struct = { foo: true, bar: ['12345', '12345', '12345'], baz: '0x00' };

const [sum, constant, struct]: [u64, u64, MyStruct] = await exported_function_foo(
'2',
Expand All @@ -20,7 +20,7 @@ it('codegens a callable function', async () => {

expect(sum).to.be.eq('0x05');
expect(constant).to.be.eq('0x03');
expect(struct).to.be.deep.eq({ foo: true, bar: ['12345', '12345', '12345'] });
expect(struct).to.be.deep.eq(my_struct);
});

it('allows passing a custom foreign call handler', async () => {
Expand All @@ -35,7 +35,7 @@ it('allows passing a custom foreign call handler', async () => {
return [];
};

const my_struct = { foo: true, bar: ['12345', '12345', '12345'] };
const my_struct = { foo: true, bar: ['12345', '12345', '12345'], baz: '0x00' };

const [sum, constant, struct]: [u64, u64, MyStruct] = await exported_function_foo(
'2',
Expand Down Expand Up @@ -102,5 +102,5 @@ it('allows passing a custom foreign call handler', async () => {

expect(sum).to.be.eq('0x05');
expect(constant).to.be.eq('0x03');
expect(struct).to.be.deep.eq({ foo: true, bar: ['12345', '12345', '12345'] });
expect(struct).to.be.deep.eq(my_struct);
});
1 change: 1 addition & 0 deletions tooling/noir_codegen/test/test_lib/src/lib.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
struct MyStruct {
foo: bool,
bar: [str<5>; 3],
baz: Field
}

struct NestedStruct {
Expand Down