diff --git a/src/bytecode.ts b/src/bytecode.ts index dd6b487..069d527 100644 --- a/src/bytecode.ts +++ b/src/bytecode.ts @@ -31,7 +31,7 @@ export type Constant = // MAKE_FUNCTION (x y) #7 -> basic function // MAKE_FUNCTION (x y=42) #7 -> with defaults // MAKE_FUNCTION (x ...rest) #7 -> variadic -// MAKE_FUNCTION (x @named) #7 -> kwargs +// MAKE_FUNCTION (x @named) #7 -> named // function parseFunctionParams(paramStr: string, constants: Constant[]): { @@ -43,12 +43,12 @@ function parseFunctionParams(paramStr: string, constants: Constant[]): { const params: string[] = [] const defaults: Record = {} let variadic = false - let kwargs = false + let named = false // Remove parens and split by whitespace const paramList = paramStr.slice(1, -1).trim() if (!paramList) { - return { params, defaults, variadic, named: kwargs } + return { params, defaults, variadic, named: named } } const parts = paramList.split(/\s+/) @@ -56,7 +56,7 @@ function parseFunctionParams(paramStr: string, constants: Constant[]): { for (const part of parts) { // Check for named args (@name) if (part.startsWith('@')) { - kwargs = true + named = true params.push(part.slice(1)) } else if (part.startsWith('...')) { @@ -91,7 +91,7 @@ function parseFunctionParams(paramStr: string, constants: Constant[]): { } } - return { params, defaults, variadic, named: kwargs } + return { params, defaults, variadic, named: named } } export function toBytecode(str: string): Bytecode /* throws */ { @@ -130,7 +130,7 @@ export function toBytecode(str: string): Bytecode /* throws */ { const bodyStr = match[2]! const body = parseInt(bodyStr.slice(1)) - const { params, defaults, variadic, named: kwargs } = parseFunctionParams(paramStr, bytecode.constants) + const { params, defaults, variadic, named } = parseFunctionParams(paramStr, bytecode.constants) // Add function definition to constants bytecode.constants.push({ @@ -139,7 +139,7 @@ export function toBytecode(str: string): Bytecode /* throws */ { defaults, body, variadic, - kwargs + named }) operandValue = bytecode.constants.length - 1 diff --git a/src/value.ts b/src/value.ts index cf27641..2445e18 100644 --- a/src/value.ts +++ b/src/value.ts @@ -14,7 +14,7 @@ export type Value = body: number, parentScope: Scope, variadic: boolean, - kwargs: boolean + named: boolean } export type Dict = Map @@ -25,7 +25,7 @@ export type FunctionDef = { defaults: Record body: number variadic: boolean - kwargs: boolean + named: boolean } export function toValue(v: any): Value /* throws */ { diff --git a/tests/exceptions.test.ts b/tests/exceptions.test.ts index 7b59566..abc466c 100644 --- a/tests/exceptions.test.ts +++ b/tests/exceptions.test.ts @@ -105,7 +105,7 @@ test("THROW - exception unwinds call stack", async () => { defaults: {}, body: 7, variadic: false, - kwargs: false + named: false }, toValue('function error'), toValue(999)