Improve errors in digiths
This commit is contained in:
parent
b0280b9d74
commit
e841106029
5 changed files with 213 additions and 156 deletions
|
|
@ -294,10 +294,18 @@ export namespace Program {
|
|||
raw_body: string,
|
||||
}
|
||||
|
||||
export function getFunction(program: Program, name: FunctionName): Result<FunctionDefinition> {
|
||||
const fn = program.function_definitions.get(name);
|
||||
if (fn === undefined) {
|
||||
return Result.error({ tag: "FunctionNotFound", name });
|
||||
}
|
||||
return Result.ok(fn);
|
||||
}
|
||||
|
||||
export function registerFunction(
|
||||
program: Program,
|
||||
{ name, body, parameters, raw_parameters, raw_body }: CreateFunction
|
||||
): Result<void> {
|
||||
): Result<FunctionName> {
|
||||
if (program.function_definitions.has(name)) {
|
||||
return Result.error({ tag: "DuplicateFunctionName", name });
|
||||
}
|
||||
|
|
@ -317,13 +325,12 @@ export namespace Program {
|
|||
program.function_definitions.set(name, { tag: "user", def: newFunction });
|
||||
program.function_definition_order.push(name);
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok(name);
|
||||
}
|
||||
|
||||
export type UpdateFunction = {
|
||||
parameters: ProductPattern[],
|
||||
body: Expr,
|
||||
raw_name: string,
|
||||
raw_parameters: string,
|
||||
raw_body: string,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue