Skip to content

Conversation

@jtenner
Copy link
Contributor

@jtenner jtenner commented Jun 9, 2021

⯈ Initial attempt on implementing arguments.length

  • I've read the contributing guidelines


/* eslint-enable @typescript-eslint/no-unused-vars */
@final
export declare class arguments {
Copy link
Contributor

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.

@jtenner
Copy link
Contributor Author

jtenner commented Jun 13, 2021

(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.

@jtenner
Copy link
Contributor Author

jtenner commented Jun 13, 2021

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);
Copy link
Contributor Author

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()

@HerrCai0907
Copy link
Member

clean outdated draft PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants