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
initial tests for arguments length #1898
base: main
Are you sure you want to change the base?
Conversation
std/assembly/builtins.ts
Outdated
@@ -2336,4 +2336,11 @@ declare function trace( | |||
@external("env", "seed") | |||
declare function seed(): f64; | |||
|
|||
/* eslint-enable @typescript-eslint/no-unused-vars */ | |||
@final | |||
export declare class arguments { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to declare a namespace? If not, that should be an added feature request.
(func $builtins/arglength1 (param $0 i32)
(local $1 i32)
(local $2 i32)
global.get $~lib/memory/__stack_pointer
i32.const 4
i32.sub
global.set $~lib/memory/__stack_pointer
call $~stack_check
global.get $~lib/memory/__stack_pointer
i32.const 0
i32.store
+ global.get $~argumentsLength
+ local.set $1
i32.const 1024
local.set $2
global.get $~lib/memory/__stack_pointer
local.get $2
i32.store
local.get $2
i32.const 2
+ call $~lib/builtins/arguments.get:length
f64.convert_i32_s
+ call $~lib/builtins/arguments.get:length
f64.convert_i32_s
f64.const 0
f64.const 0
f64.const 0
call $~lib/builtins/trace
global.get $~lib/memory/__stack_pointer
i32.const 4
i32.add
global.set $~lib/memory/__stack_pointer
) I put a plus sign before the important bits. Looks like it's calling a function instead of getting a local. |
Of course, it adds a function like this: + (func $~lib/builtins/arguments.get:length (result i32)
+ (local $0 i32)
+ global.get $~argumentsLength
+ local.set $0
+ local.get $0
+ ) 🙄 |
Remove the line. Weird. Co-authored-by: Willem Wyndham <willem@cs.umd.edu>
const mod = compiler.module; | ||
compiler.currentType = Type.i32; | ||
const local = compiler.currentFlow.lookupLocal(BuiltinNames.argumentsLengthLocal)!; | ||
return mod.local_get(local.index, TypeRef.I32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This becomes the function body of the builtin. Using arguments.length
accesses the namespace, and calls the function. This is not desired behavior.
I believe we need to override compilePropertyAccess()
⯈ Initial attempt on implementing
arguments.length