drom / wast-spec

WebAssembly AST specification
MIT License
9 stars 2 forks source link

distinguish Object and Array properties #13

Open drom opened 8 years ago

drom commented 8 years ago

We have 2 type of node hierarchical properties:

  1. Object -- scalar child
  2. Array -- vector child

it should be possible to know type of the property value by name of the property key, like:

  1. id, expr, init, test, consequent, alternate, left, right, result, module, failure, invoke -- Object
  2. body, items, params, local, segment -- Array

Find all mismatches and fix.

drom commented 8 years ago

@wanderer any thoughts?

wanderer commented 8 years ago

just add s to the end of everything that is an array?

drom commented 8 years ago

@wanderer how about body ?

wanderer commented 8 years ago

@drom idk, i'm kinda stumped on this one

drom commented 8 years ago

@wanderer I have made bunch of related changes into spec, parser, traverse, codegen. All related to the issue in hand. That made possible codegen generation. Check out new codegen! I still open for better names :smile:

Have seen your WebAssembly talks on YouTube. Impressive! You are ahead of me on this one :+1: I am going to talk about our WAST toolchain on the next South Bay SV JS meetup.

wanderer commented 8 years ago

@drom Super cool, I would love to come!... but it looks like going to be stuck here for a couple more months at least :(

Also i think you can put the event on the event list https://github.com/WebAssembly/design/blob/master/Events.md

wanderer commented 8 years ago

@drom so things like call_import and call_direct can only have one expression. Is there any reason the have those as arrays?

drom commented 8 years ago

@wanderer good catch. Approve call_import.exprs -> expr Can't find any example with call_direct...

drom commented 8 years ago

Ah! call_indirect!

left-to-right.wast:88
(func $i32_call_indirect (result i32)
  (call $reset)
  (call_indirect $i32_T
    (call $i32_callee)
    (call $i32_right)
    (call $i32_another))
  (call $get))
drom commented 8 years ago

call_import Array example !

imports.wast:7
        (call_import $print_i32_f32
            (i32.add (get_local $i) (i32.const 1))
            (f32.const 42)
        )
wanderer commented 8 years ago

:star: cool beans!

wanderer commented 8 years ago

so after some use I have found it easier to do AST transforms if I add an array 'type'. So like

{
  kind: 'block',
  body: {
     type: 'array'
     value: [ ... ]
  }
}

the extra type allow me to more easy identify and add things to blocks

drom commented 8 years ago

@wanderer why you need extra kind? have you tried https://github.com/drom/wast-traverse ? it has node and parent objects to analyze.

wanderer commented 8 years ago

@drom here is an example

(block
  (statement)
  (statement that has a possible `br`)
  (inject node here)
  (statement)
)

i need to inject a statement into every block after a possible branch condition. So i could do this by checking if the parent is a func, loop, block, ect. Or i can just add a fake type 'array' and check for array.

drom commented 8 years ago

@wanderer I am not sure about kind:Array idea. It adds to the complexity of the AST. IMHO