Skip to content

Commit

Permalink
refactor: rename hint parser variables to a explicit and generic name
Browse files Browse the repository at this point in the history
  • Loading branch information
zmalatrax committed Jul 15, 2024
1 parent afe1903 commit 2cf3176
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/hints/allocSegment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Relocatable } from 'primitives/relocatable';
import { Register } from 'vm/instruction';
import { VirtualMachine } from 'vm/virtualMachine';
import { HintName } from 'hints/hintName';
import { allocSegmentZod } from './allocSegment';
import { allocSegmentParser } from './allocSegment';

const ALLOC_SEGMENT = {
AllocSegment: {
Expand All @@ -17,7 +17,7 @@ const ALLOC_SEGMENT = {

describe('AllocSegment', () => {
test('should properly parse AllocSegment hint', () => {
const hint = allocSegmentZod.parse(ALLOC_SEGMENT);
const hint = allocSegmentParser.parse(ALLOC_SEGMENT);
expect(hint).toEqual({
type: HintName.AllocSegment,
dst: {
Expand All @@ -28,7 +28,7 @@ describe('AllocSegment', () => {
});

test('should properly execute AllocSegment hint', () => {
const hint = allocSegmentZod.parse(ALLOC_SEGMENT);
const hint = allocSegmentParser.parse(ALLOC_SEGMENT);
const vm = new VirtualMachine();
vm.memory.addSegment();
vm.memory.addSegment();
Expand Down
4 changes: 2 additions & 2 deletions src/hints/allocSegment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { cellRef, CellRef } from 'hints/hintParamsSchema';
import { HintName } from 'hints/hintName';

/** Zod object to parse AllocSegment hint */
export const allocSegmentZod = z
export const allocSegmentParser = z
.object({ AllocSegment: z.object({ dst: cellRef }) })
.transform(({ AllocSegment: { dst } }) => ({
type: HintName.AllocSegment,
Expand All @@ -17,7 +17,7 @@ export const allocSegmentZod = z
*
* Add a new segment and store its pointer to `dst`
*/
export type AllocSegment = z.infer<typeof allocSegmentZod>;
export type AllocSegment = z.infer<typeof allocSegmentParser>;

/**
* Add a new segment and store its pointer at `dst`
Expand Down
6 changes: 3 additions & 3 deletions src/hints/hintSchema.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { z } from 'zod';

import { allocSegmentZod } from './allocSegment';
import { testLessThanZod } from './testLessThan';
import { allocSegmentParser } from './allocSegment';
import { testLessThanParser } from './testLessThan';

/** Zod object to parse any implemented hints */
const hint = z.union([allocSegmentZod, testLessThanZod]);
const hint = z.union([allocSegmentParser, testLessThanParser]);

/** Zod object to parse an array of hints grouped on a given PC */
export const hintsGroup = z.tuple([z.number(), z.array(hint)]);
Expand Down
6 changes: 3 additions & 3 deletions src/hints/testLessThan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Register } from 'vm/instruction';
import { VirtualMachine } from 'vm/virtualMachine';
import { OpType } from 'hints/hintParamsSchema';
import { HintName } from 'hints/hintName';
import { testLessThanZod } from './testLessThan';
import { testLessThanParser } from './testLessThan';

const TEST_LESS_THAN = {
TestLessThan: {
Expand All @@ -27,7 +27,7 @@ const TEST_LESS_THAN = {

describe('TestLessThan', () => {
test('should properly parse TestLessThan hint', () => {
const hint = testLessThanZod.parse(TEST_LESS_THAN);
const hint = testLessThanParser.parse(TEST_LESS_THAN);

expect(hint).toEqual({
type: HintName.TestLessThan,
Expand All @@ -53,7 +53,7 @@ describe('TestLessThan', () => {
[new Felt(-2n), new Felt(0n)],
[new Felt(2n), new Felt(1n)],
])('should properly execute TestLessThan hint', (lhs, expected) => {
const hint = testLessThanZod.parse(TEST_LESS_THAN);
const hint = testLessThanParser.parse(TEST_LESS_THAN);
const vm = new VirtualMachine();
vm.memory.addSegment();
vm.memory.addSegment();
Expand Down
4 changes: 2 additions & 2 deletions src/hints/testLessThan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { cellRef, resOp, CellRef, ResOp } from 'hints/hintParamsSchema';
import { HintName } from 'hints/hintName';

/** Zod object to parse TestLessThan hint */
export const testLessThanZod = z
export const testLessThanParser = z
.object({
TestLessThan: z.object({ lhs: resOp, rhs: resOp, dst: cellRef }),
})
Expand All @@ -23,7 +23,7 @@ export const testLessThanZod = z
* Store true at `dst` if value at `lhs` is stricty inferior to value at `rhs`.
* Store false otherwise
*/
export type TestLessThan = z.infer<typeof testLessThanZod>;
export type TestLessThan = z.infer<typeof testLessThanParser>;

/**
* TestLessThan hint
Expand Down

0 comments on commit 2cf3176

Please sign in to comment.