ConvertToBinary:incorrect index for 'value' variable of 'argument' type

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

ConvertToBinary:incorrect index for 'value' variable of 'argument' type

kraftwerk1611
Hi,

I am writing code to compile main.jack of ConvertToBinary test program of Project 11.

Referring to Fig 11.6 on page 236 in book, in every new symbol table for subroutine, I add 'this' as first argument type entry like
name=this
Type=className
Kind=argument
index=0

This seems to be causing problem when compiling following function in main.jack

function void convert(int value) {
    var int mask, position;
    var boolean loop;
   
    let loop = true;
    while (loop) {
       let position = position + 1;
       let mask = Main.nextMask(mask);
   
       if (~(position > 16)) {
   
           if (~((value & mask) = 0)) {
               do Memory.poke(8000 + position, 1);
               }
           else {
               do Memory.poke(8000 + position, 0);
             }    
       }
       else {
           let loop = false;
       }
    }
    return;
    }


What seems to happening is that in the highlighted command below the argument variable when pushed on stack is being pushed as 'push argument 1' unlike the code generated by the supplied Jack Compiler, which prints this line as 'push argument 0'.

Outputs from my compiler and from supplied Jack Compiler are pasted below side-by-side.




The symbol tables when compiling the file are as below




There might be other problems with the code but this one seems looks so obvious.

Does it have something to do with the symbol tables or does it have to do with how I am writing code for if-else.

Thanks.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ConvertToBinary:incorrect index for 'value' variable of 'argument' type

cadet1620
Administrator
Only add 'this' as the first argument to method subroutines.

function subroutines do not have a "this" and constructor subroutines create their own "this".

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ConvertToBinary:incorrect index for 'value' variable of 'argument' type

kraftwerk1611
thanks.

This problem solve.

Loading...