Skip to content
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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jtenner
Copy link
Contributor

@jtenner jtenner commented Jun 9, 2021

⯈ Initial attempt on implementing arguments.length

  • I've read the contributing guidelines

src/builtins.ts Outdated Show resolved Hide resolved
@@ -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 {
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()

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.

None yet

2 participants