Bug in JackCompiler, bad min int?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Bug in JackCompiler, bad min int?

zenspider
Still using 2.5.x on osx, I found the following:

// -*- c -*-

class ParserBug2 {
  function void init() {
    var int n;

    let n = 32767;
    let n = -32768;

    return;
  }
}

// In ParserBug2.jack (line 8): In subroutine init: Integer constant too big

Yet, http://en.wikipedia.org/wiki/16-bit says:

A 16-bit integer can store 216 (or 65,536) distinct values. In an unsigned representation, these values are the integers between 0 and 65,535; using two's complement, possible values range from −32,768 to 32,767. Hence, a processor with 16-bit memory addresses can directly access 64 KiB of byte-addressable memory.

I tried tracking down the error message in the source and couldn't find it.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Bug in JackCompiler, bad min int?

cadet1620
Administrator
zenspider wrote
Still using 2.5.x on osx, I found the following:


// -*- c -*-

class ParserBug2 {
  function void init() {
    var int n;

    let n = 32767;
    let n = -32768;

    return;
  }
}

// In ParserBug2.jack (line 8): In subroutine init: Integer constant too big
This isn't a bug. It is an inconvenient feature of the language.

The Jack language defines "integerConstant: A decimal number in the range 0..32767."
   
"-32768" is treated as the expression "-(32768)" which is indeed outside the range for integerConstant.

[There are lots of compromises like this in Jack so that it is easier to write the compiler.]

--Mark
Loading...