   while node[0] isnt 'body' then node = node.parent
   node
 
-
+# Used to report the AST node where the error happened
+@CompilerError =
+  class CompilerError extends Error
+    constructor: (@astNode, @message, args...) ->
+      assert @astNode instanceof Array
+      assert typeof @message is 'string'
+      assert not args.length
 
 # # Public interface to this module
 

            {type: 'X'}
          else
            v = vars[name]
            assert v, "Symbol '#{name}' referenced before assignment"
            v.used = true
            v
        when 'lambda'

    #     A←5       ⍝ returns 5
    #     A×A←2 5   ⍝ returns 4 25
    when 'assign'
      if not (node[1] instanceof Array and
              node[1].length is 2 and
              node[1][0] is 'symbol')
        throw new CompilerError node,
          'Compound assignment is not supported.'
      name = node[1][1]
      assert typeof name is 'string'
      if name is '∇'
        throw new CompilerError node, 'Assignment to ∇ is not allowed.'
      vars = closestScope(node).vars
      if (v = vars["set_#{name}"])?.type is 'F'
        v.used = true
