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

fix enums name mistmatch, argument types and missing members #42

Merged
merged 15 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/algo-ts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@algorandfoundation/algorand-typescript",
"version": "0.0.1-alpha.15",
"version": "0.0.1-alpha.16",
"description": "This package contains definitions for the types which comprise Algorand TypeScript which can be compiled to run on the Algorand Virtual Machine using the Puya compiler.",
"private": false,
"main": "index.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/algo-ts/src/impl/primitives.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { biguint, BigUintCompat, bytes, BytesCompat, uint64, Uint64Compat } from '../index'
import { encodingUtil } from '../internal'
import { base32ToUint8Array } from './base-32'
import {
base64ToUint8Array,
Expand Down Expand Up @@ -307,6 +308,7 @@ export class BytesCls extends AlgoTsPrimitiveCls {
static fromCompat(v: StubBytesCompat | Uint8Array | undefined): BytesCls {
if (v === undefined) return new BytesCls(new Uint8Array())
if (typeof v === 'string') return new BytesCls(utf8ToUint8Array(v))
if (typeof v == 'bigint') return new BytesCls(encodingUtil.bigIntToUint8Array(v))
if (v instanceof BytesCls) return v
if (v instanceof Uint8Array) return new BytesCls(v)
internalError(`Cannot convert ${nameOfType(v)} to bytes`)
Expand Down
1 change: 1 addition & 0 deletions packages/algo-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './state'
export * as itxn from './itxn'
export * as gtxn from './gtxn'
export { TransactionType } from './transactions'
export { Base64, Ec, Ecdsa, VrfVerify } from './op-types'
2 changes: 0 additions & 2 deletions packages/algo-ts/src/op.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,3 @@ export const AssetHolding = createObjectProxy('AssetHolding')
export const AssetParams = createObjectProxy('AssetParams')
export const Block = createObjectProxy('Block')
export const Box = createObjectProxy('Box')

export { VrfVerify } from './op-types'
2 changes: 1 addition & 1 deletion packages/algo-ts/src/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BigUintCls, BytesCls, getNumber, Uint64Cls } from './impl/primitives'
export type Uint64Compat = uint64 | bigint | boolean | number
export type BigUintCompat = bigint | bytes | number | boolean
export type StringCompat = string
export type BytesCompat = bytes | string
export type BytesCompat = bigint | bytes | string
boblat marked this conversation as resolved.
Show resolved Hide resolved

/**
* An unsigned integer of exactly 64 bits
Expand Down
4 changes: 2 additions & 2 deletions packages/algo-ts/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { biguint, BigUintCompat, BytesCompat, StringCompat, uint64, Uint64Compat } from './primitives'
import { ctxMgr } from './execution-context'
import { AssertError, AvmError } from './impl/errors'
import { toBytes } from './impl/primitives'
import { biguint, BigUintCompat, BytesCompat, StringCompat, uint64, Uint64Compat } from './primitives'

export function log(...args: Array<Uint64Compat | BytesCompat | BigUintCompat | StringCompat>): void {
ctxMgr.instance.log(args.map(toBytes).reduce((left, right) => left.concat(right)))
Expand All @@ -14,7 +14,7 @@ export function assert(condition: unknown, message?: string): asserts condition
}

export function err(message?: string): never {
throw new AvmError(message ?? 'Err')
throw new AvmError(message ?? 'err opcode executed')
}

type NumericComparison<T> = T | { lessThan: T } | { greaterThan: T } | { greaterThanEq: T } | { lessThanEq: T } | { between: [T, T] }
Expand Down
63 changes: 63 additions & 0 deletions src/awst_build/eb/bytes-expression-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ export class BytesExpressionBuilder extends InstanceExpressionBuilder<InstanceTy
)
case 'bitwiseInvert':
return new BytesInvertBuilder(this._expr)
case 'bitwiseAnd':
return new BitwiseAndExpressionBuilder(this._expr)
case 'bitwiseOr':
return new BitwiseOrExpressionBuilder(this._expr)
case 'bitwiseXor':
return new BitwiseXorExpressionBuilder(this._expr)
boblat marked this conversation as resolved.
Show resolved Hide resolved
case 'toString':
return new ToStringBuilder(this._expr)
case 'concat':
Expand Down Expand Up @@ -273,6 +279,63 @@ export class BytesInvertBuilder extends ParameterlessFunctionBuilder {
}
}

export class BitwiseAndExpressionBuilder extends FunctionBuilder {
constructor(private expr: awst.Expression) {
super(expr.sourceLocation)
}

call(args: ReadonlyArray<NodeBuilder>, typeArgs: ReadonlyArray<PType>, sourceLocation: SourceLocation): NodeBuilder {
const [other] = requireExpressionsOfType(args, [bytesPType], sourceLocation)
boblat marked this conversation as resolved.
Show resolved Hide resolved
return new BytesExpressionBuilder(
nodeFactory.bytesBinaryOperation({
wtype: wtypes.bytesWType,
left: this.expr,
right: other,
op: BytesBinaryOperator.bitAnd,
sourceLocation,
}),
)
}
}

export class BitwiseOrExpressionBuilder extends FunctionBuilder {
constructor(private expr: awst.Expression) {
super(expr.sourceLocation)
}

call(args: ReadonlyArray<NodeBuilder>, typeArgs: ReadonlyArray<PType>, sourceLocation: SourceLocation): NodeBuilder {
const [other] = requireExpressionsOfType(args, [bytesPType], sourceLocation)
return new BytesExpressionBuilder(
nodeFactory.bytesBinaryOperation({
wtype: wtypes.bytesWType,
left: this.expr,
right: other,
op: BytesBinaryOperator.bitOr,
sourceLocation,
}),
)
}
}

export class BitwiseXorExpressionBuilder extends FunctionBuilder {
constructor(private expr: awst.Expression) {
super(expr.sourceLocation)
}

call(args: ReadonlyArray<NodeBuilder>, typeArgs: ReadonlyArray<PType>, sourceLocation: SourceLocation): NodeBuilder {
const [other] = requireExpressionsOfType(args, [bytesPType], sourceLocation)
return new BytesExpressionBuilder(
nodeFactory.bytesBinaryOperation({
wtype: wtypes.bytesWType,
left: this.expr,
right: other,
op: BytesBinaryOperator.bitXor,
sourceLocation,
}),
)
}
}

export class ToStringBuilder extends ParameterlessFunctionBuilder {
constructor(private expr: awst.Expression) {
super(
Expand Down
4 changes: 2 additions & 2 deletions src/awst_build/eb/op-module-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { SourceLocation } from '../../awst/source-location'
import { CodeError, InternalError } from '../../errors'
import { enumerate, invariant } from '../../util'
import type { IntrinsicOpGrouping, IntrinsicOpMapping } from '../op-metadata'
import { OP_METADATA } from '../op-metadata'
import { OP_METADATA, VOID_OPS } from '../op-metadata'
import type { PType } from '../ptypes'
import { IntrinsicEnumType, IntrinsicFunctionGroupType, IntrinsicFunctionType, stringPType } from '../ptypes'
import { typeRegistry } from '../type-registry'
Expand Down Expand Up @@ -33,7 +33,7 @@ export class IntrinsicOpGroupBuilder extends NodeBuilder {
}
const metaData = this.opGrouping.ops[name]

if (metaData.signatures.some((s) => s.argNames.length)) {
if (VOID_OPS.includes(metaData.op) || metaData.signatures.some((s) => s.argNames.length)) {
boblat marked this conversation as resolved.
Show resolved Hide resolved
return new GroupedIntrinsicOpBuilder(sourceLocation, metaData)
}

Expand Down
Loading