[fpc-pascal] Re: jvmbackend merge
I tried building the compiler, it passes but I have to do some changes. The make process fails after compiling the compiler ended with some warnings regarding constructing a class with abstract method in compiler/jvm/hlcgcpu.pas. The compiler seems to return exit code 1 on warnings and that's the cause of the failure. For the workaround, I've added these methods (with empty body implementation) to thlcgjvm class: procedure a_bit_scan_reg_reg(list: TAsmList; reverse: boolean; size: tdef; src, dst: tregister); override; procedure a_loadmm_loc_reg(list: TAsmList; fromsize, tosize: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);override; procedure g_copyvariant(list : TAsmList;const source,dest : treference;vardef:tvariantdef);override; procedure g_overflowcheck(list: TAsmList; const Loc:tlocation; def:tdef); override; procedure g_overflowCheck_loc(List:TAsmList;const Loc:TLocation;def:TDef;var ovloc : tlocation);override; procedure g_stackpointer_alloc(list : TAsmList;size : longint); override; procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);override; procedure g_adjust_self_value(list:TAsmList;procdef: tprocdef;ioffset: aint);override; procedure g_local_unwind(list: TAsmList; l: TAsmLabel);override; -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/jvmbackend-merge-tp5709941p5709947.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Accessing open array
Hi, Im trying to access an open array but I get a runtime error. I googled a bit, and found some suggestions, but for me they don't work. It's actually a port of some C-library I want to use on a STM32-processor. This is my test-code : program LCDtest1; type TArray = array of byte; var nCols : cardinal; nRows : cardinal; nBytes : cardinal; pFont : ^TArray; {$include fonts.inc} begin // get pointer to the beginning of the selected font table pFont:=@FONT6x8; writeln('0'); setlength(pFont^,8); <-- here it crashes writeln('1'); nCols:=pFont^[0]; //nCols:=pFont^[low(pFont^)]; {writeln('2'); nRows:=pFont^[1]; writeln('3'); nBytes:=pFont^[2];} writeln('end'); end. I didn't have the setlength at first, then it crashed at the first access of the array (ncols:=...). The include file contains this (only partly shown) : originally : const FONT6x8 : array[0..96] of array[0..7] of byte = ( ($06,$08,$08,$00,$00,$00,$00,$00), // columns, rows, num_bytes_per_char ($00,$00,$00,$00,$00,$00,$00,$00), // space $20 ($20,$20,$20,$20,$20,$00,$20,$00), // ! ($50,$50,$50,$00,$00,$00,$00,$00), // " ($50,$50,$F8,$50,$F8,$50,$50,$00), // # ... modified (with the same error) : const FONT6x8 : array[0..775] of byte = ( ($06,$08,$08,$00,$00,$00,$00,$00, // columns, rows, num_bytes_per_char ($00,$00,$00,$00,$00,$00,$00,$00, // space $20 ($20,$20,$20,$20,$20,$00,$20,$00, // ! ($50,$50,$50,$00,$00,$00,$00,$00, // " ($50,$50,$F8,$50,$F8,$50,$50,$00, // # ... Any suggestions how I can correct my code ? Thanks, Koenraad Lelong. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: jvmbackend merge
On 03.06.2012 17:48, leledumbo wrote: I tried building the compiler, it passes but I have to do some changes. The make process fails after compiling the compiler ended with some warnings regarding constructing a class with abstract method in compiler/jvm/hlcgcpu.pas. The compiler seems to return exit code 1 on warnings and that's the cause of the failure. For the workaround, I've added these methods (with empty body implementation) to thlcgjvm class: You currently need to compile with "ALLOW_WARNINGS=1" when compiling the JVM compiler. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Accessing open array
On 03-06-12 17:53, Koenraad Lelong wrote: Hi, Im trying to access an open array but I get a runtime error. I googled a bit, and found some suggestions, but for me they don't work. Forgot to say : runtime error is 216. modified (with the same error) : const FONT6x8 : array[0..775] of byte = ( $06,$08,$08,$00,$00,$00,$00,$00, // columns, rows, num_bytes_per_char $00,$00,$00,$00,$00,$00,$00,$00, // space $20 $20,$20,$20,$20,$20,$00,$20,$00, // ! $50,$50,$50,$00,$00,$00,$00,$00, // " $50,$50,$F8,$50,$F8,$50,$50,$00, // # ... This is my actual code. Koenraad Lelong. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Accessing open array
On 03 Jun 2012, at 17:53, Koenraad Lelong wrote: > Im trying to access an open array but I get a runtime error. You are trying to use a pointer to a static array as a pointer to a dynamic array (not an open array; have a look at e.g. http://rvelthuis.de/articles/articles-openarr.html to read about the differences between all the kinds of array types). It's normal that this crashes. A static array is something completely different than a dynamic array. If you add {$T+} to your source code (to enable typed pointers), the compiler will tell you that those pointer types are incompatible. > Any suggestions how I can correct my code ? It is not possible to declare an initialized dynamic array. You have to initialize it dynamically, e.g. via var arr: tarray; begin setlength(arr,8); move(FONT6x8[low(FONT6x8)],arr[low(arr)],8); end; Note: the extra [low(arr)] is required for the dynamic array (because a dynamic array is an implicit pointer, and without the [low(arr)] you will start overwriting that implicit pointer itself, along with everything coming after it in memory). It's not required for the static array, but it's good practice to always write it in order to avoid getting nasty bugs when changing the type of the array later on for some reason. And using low() rather than 0 protects you in case the lower bound of the array changes for some reason. Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Accessing open array
Koenraad Lelong wrote: Hi, Im trying to access an open array but I get a runtime error. I googled a bit, and found some suggestions, but for me they don't work. It's actually a port of some C-library I want to use on a STM32-processor. This is my test-code : program LCDtest1; type TArray = array of byte; var nCols : cardinal; nRows : cardinal; nBytes : cardinal; pFont : ^TArray; {$include fonts.inc} begin // get pointer to the beginning of the selected font table pFont:=@FONT6x8; writeln('0'); setlength(pFont^,8); <-- here it crashes I didn't have the setlength at first, then it crashed at the first access of the array (ncols:=...). The include file contains this (only partly shown) : originally : const FONT6x8 : array[0..96] of array[0..7] of byte = ( Assuming that in your current implementation FONT6x8 is a table at an absolute location in memory... I don't think you can do that, since a dynamic array (which I think is what you're trying to use) is nowt but a descriptor block which contains a pointer into the heap. Try something like typeTFONT6x8= array[0..96] of array[0..7] of byte; PFONT6x8= ^TFONT6x8; var fontTable: PFONT6x8; Force your absolute address into fontTable, then dereference to get at the content. -- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Accessing open array
Hi, Looking at the C-code again, I saw I could actually use a pointer to byte, instead of a pointer to an array of bytes. So I'm using this : program LCDtest1; var nCols : cardinal; nRows : cardinal; nBytes : cardinal; pFont : ^byte; {$include fonts.inc} begin // get pointer to the beginning of the selected font table pFont:=@FONT6x8; nCols:=pFont^; nRows:=(pFont+1)^; nBytes:=(pFont+2)^; end. Now my library works. Thanks, Koenraad Lelong. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal