Skip to content

Commit

Permalink
Handle case where no arguments are passed to a buffer assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
captbaritone committed May 6, 2020
1 parent 94f6305 commit 568448c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
megabuf() = 10;
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ exports[`assign_to_buffer_too_many_args.eel 2`] = `
| ^"
`;

exports[`assign_to_buffer_zero_args.eel 1`] = `"Expected 1 argument when assinging to a buffer but got 0."`;

exports[`assign_to_buffer_zero_args.eel 2`] = `
"
> 1 | megabuf() = 10;
| ^^^^^^^^^"
`;

exports[`assign_to_non_buff_function_call.eel 1`] = `"The only function calls which may be assigned to are \`gmegabuf()\` and \`megabuf()\`."`;

exports[`assign_to_non_buff_function_call.eel 2`] = `
Expand Down
8 changes: 4 additions & 4 deletions packages/compiler/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ export function emit(ast: Ast, context: CompilerContext): number[] {
if (ast.left.type == "CALL_EXPRESSION") {
const localIndex = context.resolveLocalF64();
const { operator, left } = ast;
if (ast.left.arguments.length !== 1) {
if (left.arguments.length !== 1) {
throw createUserError(
`Expected 1 argument when assinging to a buffer but got ${ast.left.arguments.length}.`,
ast.left.arguments[1].loc,
`Expected 1 argument when assinging to a buffer but got ${left.arguments.length}.`,
left.arguments.length === 0 ? left.loc : left.arguments[1].loc,
context.rawSource
);
}
Expand All @@ -347,7 +347,7 @@ export function emit(ast: Ast, context: CompilerContext): number[] {
const addOffset = emitAddMemoryOffset(bufferName);

const index = [
...emit(ast.left.arguments[0], context),
...emit(left.arguments[0], context),
op.local_tee,
...unsignedLEB128(localIndex),
op.i32_trunc_s_f64,
Expand Down

0 comments on commit 568448c

Please sign in to comment.