Commit Graph

197 Commits

Author SHA1 Message Date
Jonas Maebe
26ee54b1a2 * fixed compilation with 2.4.4
git-svn-id: branches/jvmbackend@18778 -
2011-08-20 08:35:19 +00:00
Jonas Maebe
2428ea65c1 * replaced the old hack for non-formal var/out/constref support with
a generalized version of the formal var/out/constref support (this
    also fixes passing string[xyz] expressions to non-formal var/out/constref
    parameters)

git-svn-id: branches/jvmbackend@18774 -
2011-08-20 08:34:46 +00:00
Jonas Maebe
ee77d5a6f2 * some changes to handleformalcopyoutpara() so that in the future it can
also handle non-formal parameters
  * do not copy in the original value in handleformalcopyoutpara() if it's
    an out parameter

git-svn-id: branches/jvmbackend@18772 -
2011-08-20 08:34:36 +00:00
Jonas Maebe
d7cff1cd31 * give an error when trying to typecast a unicodestring into a pwidechar
on the JVM target (we can't access the characters of a JLString as an
    array)

git-svn-id: branches/jvmbackend@18769 -
2011-08-20 08:34:21 +00:00
Jonas Maebe
224aae8993 + support for typecasting ansistrings into pchars on the JVM platform
+ support for indexing pointers as arrays on the JVM platform (with
    JVM-provided range checking, obviously)

git-svn-id: branches/jvmbackend@18768 -
2011-08-20 08:34:16 +00:00
Jonas Maebe
27731e342c + support for array-of-const on the JVM target. Even though the
implementation is a bit different from that on native targets, the
    result is quite compatible

git-svn-id: branches/jvmbackend@18765 -
2011-08-20 08:34:00 +00:00
Jonas Maebe
d0e8cd1637 + support for dereferencing any kind of pointer type
git-svn-id: branches/jvmbackend@18763 -
2011-08-20 08:33:49 +00:00
Jonas Maebe
1a0913c462 * fixed proc_to_procvar() type conversion in case the target procvar
type was generated on-the-fly rather than specified to the
    type conversion node

git-svn-id: branches/jvmbackend@18762 -
2011-08-20 08:33:45 +00:00
Jonas Maebe
687e9fb6dc * fixed fully qualified class names passed to JLClass.forName()
(components must be separated by '.', not '/')

git-svn-id: branches/jvmbackend@18761 -
2011-08-20 08:33:40 +00:00
Jonas Maebe
dd32efa9ff + cstring_to_pchar type conversion support
* fixed AnsiCharArrayClass.CreateFromLiteralStringBytes() declaration
    (no maxlength parameter)

git-svn-id: branches/jvmbackend@18760 -
2011-08-20 08:33:35 +00:00
Jonas Maebe
4647aa3f15 * don't copy back constref parameter values after the call
git-svn-id: branches/jvmbackend@18759 -
2011-08-20 08:33:30 +00:00
Jonas Maebe
76de70e683 * since enums are represented by classes in the JVM, initialize global
variables, class/record fields and arrays with enumtype(0) on
    creation, so that using them without explicitly initializing them
    doesn't cause a null-pointer exception. If enumtype(0) is not a
    valid enum, they are not initialized (and since they wouldn't have
    a valid value on native targets either in that case, an exception
    on use is acceptable)

git-svn-id: branches/jvmbackend@18755 -
2011-08-20 08:33:02 +00:00
Jonas Maebe
d33f71460f * don't initialize static arrays of records twice (g_newarray already
initializes them)

git-svn-id: branches/jvmbackend@18753 -
2011-08-20 08:32:52 +00:00
Jonas Maebe
da5bd3b0bd * use invokespecial for "strict private" (= Java "private") rather than for
plain "private" (~ Java "package") methods

git-svn-id: branches/jvmbackend@18750 -
2011-08-20 08:32:37 +00:00
Jonas Maebe
7f22a2f223 + support for range checking calculations with hlcgobj
* added runerror number to JVM FpcRunTimeError exceptions
  * enabled calling errorproc when a run time error occurs on the
    JVM target

git-svn-id: branches/jvmbackend@18749 -
2011-08-20 08:32:31 +00:00
Jonas Maebe
f4690f90ad * keep maximum used evaluation stack size up-to-date when putting a
default return value on the stack for fpu routines

git-svn-id: branches/jvmbackend@18744 -
2011-08-20 08:31:53 +00:00
Jonas Maebe
fe82e2481b + import java.lang.Math in the system unit
+ include mathh.inc in the system unit, implement most routines based
    on java.lang.Math, and use (an unmodified!) genmath for the rest
  - removed now obsolete jmathh.inc (was partial copy of mathh.inc)
  - removed commented out overrides for several math routines in
    njvminl (doesn't make sense to handle them inline in the compiler)

git-svn-id: branches/jvmbackend@18742 -
2011-08-20 08:31:24 +00:00
Jonas Maebe
af489b99de * fixed handling of currency in int_to_int conversions
git-svn-id: branches/jvmbackend@18741 -
2011-08-20 08:31:12 +00:00
Jonas Maebe
72c81d9eb1 * always create a new call node when replacing virtual class method calls
with wrapper calls, because the parameter nodes are already bound to the
    paravarsyms of the current procdef so simply replacing the procsym and
    procdef is not enough

git-svn-id: branches/jvmbackend@18739 -
2011-08-20 08:30:38 +00:00
Jonas Maebe
c2f2a8c900 * make sure that the expression representing the ansi/unicodestring argument
to length is never evaluated more than once

git-svn-id: branches/jvmbackend@18736 -
2011-08-20 08:30:02 +00:00
Jonas Maebe
707b41b159 + allocate space of local typed consts that are implicit pointer types
in the enclosing class/unit init code

git-svn-id: branches/jvmbackend@18735 -
2011-08-20 08:29:47 +00:00
Jonas Maebe
9253d990d9 * use the signedness of the comparison operation rather than of the
types involved to determine whether or not the comparison is
    unsigned (they don't always match due to bugs in the compiler,
    and the sign of the comparison operation is what's used in
    other code generators too)

git-svn-id: branches/jvmbackend@18734 -
2011-08-20 08:29:36 +00:00
Jonas Maebe
8fcc8f92ca * allow taking the address of var-parameters in normal Pascal code (not just
via internal njvmaddrnodes), because we need it for procvar dispatching

git-svn-id: branches/jvmbackend@18732 -
2011-08-20 08:29:11 +00:00
Jonas Maebe
b3072b3dab * extracted the code to deal with static fields into a routine
(make_field_static() ) and replaced semi-duplicates of that
    code with calls to this routine
  * made the handling of static fields for the JVM target more
    similar to that on the other targets, so that class properties
    now also work there (-> updated JVM-specific code in several
    places to deal with this new handling)

git-svn-id: branches/jvmbackend@18723 -
2011-08-20 08:27:48 +00:00
Jonas Maebe
7419c97e0a * do not call the virtual class method/constructor dispatching lookup
when calling the inherited version, since that one is also known at
    compile time

git-svn-id: branches/jvmbackend@18712 -
2011-08-20 08:26:52 +00:00
Jonas Maebe
1d0388d40a + support for virtual constructors for the JVM platform. We simply
create a virtual class (factory) method that calls the constructor,
    and then let the existing support for virtual class methods handle
    everything

git-svn-id: branches/jvmbackend@18710 -
2011-08-20 08:26:40 +00:00
Jonas Maebe
2a9043f4bc * keep the node flags when replacing a call to a virtual class method with
a call to its wrapper

git-svn-id: branches/jvmbackend@18708 -
2011-08-20 08:26:30 +00:00
Jonas Maebe
7d8cbe80f5 + support for virtual class methods on the JVM platform. The JVM does not
support those natively, so they are emulated via the procvar infrastructure
    (and hence not very fast). Could probably be optimized somewhat by adding
    a cache (hashmap of procvars) to the class hierarchies, maybe in the
    future.

git-svn-id: branches/jvmbackend@18704 -
2011-08-20 08:26:11 +00:00
Jonas Maebe
cd6b8b9dd1 * correctly create procvars for procdefs that have an import_name set
git-svn-id: branches/jvmbackend@18703 -
2011-08-20 08:26:05 +00:00
Jonas Maebe
249b56d742 * fixed calling non-static class methods via procvars: since we can't known
on the caller side whether it's a normal or class method that we are
    calling, add the self-class parameter inside the invoke method if
    necessary (by simply counting the number of parameters and inserting
    it if we're one short)

git-svn-id: branches/jvmbackend@18699 -
2011-08-20 08:25:44 +00:00
Jonas Maebe
d8977b0342 - disabled the set constant caching via static variables for now because
their initialization can cause races between the unit they are declared
    in and the class constructor they are initialized in (even if both
    would be moved to the unit initialization code, a class constructor
    using the set constant could run before the unit initialization code has
    run)

git-svn-id: branches/jvmbackend@18698 -
2011-08-20 08:25:39 +00:00
Jonas Maebe
c8c75d7e1d * convert non-constant enums in in-expressions to longint if we use the
generic jumps code

git-svn-id: branches/jvmbackend@18697 -
2011-08-20 08:25:33 +00:00
Jonas Maebe
4557938e62 - removed no longer needed/used {$ifndef nounsupported} code
git-svn-id: branches/jvmbackend@18692 -
2011-08-20 08:25:08 +00:00
Jonas Maebe
979f55e1db + support for procedural variables for the JVM target
o every porocedural variable type is represented by a class with one
     public "invoke" method whose signature matches the signature of the
     procvar
   o internally, dispatching happens via java.lang.reflect.Method.invoke().
     WARNING: while this allows calling private/protected or other methods
     that are normally not accessible from another context, a security
     manger can override this. If such a security manager is installed,
     most procvars will cause security exceptions
   o such dispatching also requires that all arguments are wrapped, but
     that's done in the compiler-generated body of the invoke method,
     so that procvars can also be called conveniently from Java code
   o typecasting between a procedure of object and tmethod is supported,
     as well as Delphi-style replacing of only the method pointer via
     @procvar1=@procvar2.
   o nested procvars are not yet supported, but most of the basic
     infrastructure for them is already present
  * all units/programs now get an internal __FPC_JVM_Module_Class_Alias$
    type when compiled for the JVM target, which is an "external" class
    that maps to the unit name. This is required to look up the
    JLRMethod instances for regular functions/procedures
  + new tabstractprocdef.copyas() method that allows to create a procvar
    from a procdef and vice versa

git-svn-id: branches/jvmbackend@18690 -
2011-08-20 08:24:58 +00:00
Jonas Maebe
834f8da885 + added extra parameter to jvmgetboxtype() to indicate whether all integer
types should be mapped onto jllong or rather onto the closes matching type

git-svn-id: branches/jvmbackend@18685 -
2011-08-20 08:24:29 +00:00
Jonas Maebe
61fd6ca4ee * zero-extend small unsigned integer parameters on function *entry*, because
the functions may be called from Java code or indirectly and in that case
    there's no way to guarantee that they'll be zero-extended on the caller
    side

git-svn-id: branches/jvmbackend@18684 -
2011-08-20 08:24:24 +00:00
Jonas Maebe
cef61300ff + ttgobj.gethltemptyped() routine for allocating managed types with high level
code generator support
  * refactored some internal temp generator code

git-svn-id: branches/jvmbackend@18681 -
2011-08-20 08:24:07 +00:00
Jonas Maebe
085d0efead * some fixes for fake procvar support
git-svn-id: branches/jvmbackend@18680 -
2011-08-20 08:24:02 +00:00
Jonas Maebe
d6966e545b + support for formal var/out parameters on the JVM target:
o primitive types are first boxed
   o the parameter is passed inside an array of one class instance
   o changing the parameter inside the routine (by assigning a value to it
     like in Delphi.NET and different from regular Pascal code) will replace
     this class instance (again boxing the value if required)
   o on return, the class instance is extracted, unboxed if required, and
     assigned back to the original location
   o formal const parameters are handled without the extra array indirection,
     since they cannot be changed

  TODO: while writing tjvmcallparanode.handleformalcopyoutpara() I forgot that
    calling getcopy on ttemprefnodes whose ttempcreatenode hasn't been copied
    yet works fine, so that code is more complex than needed. Still have to
    fix.

git-svn-id: branches/jvmbackend@18675 -
2011-08-20 08:23:33 +00:00
Jonas Maebe
5bf16214cd * changed initialization of records from constructing a new instance and
copying that over the old one into calling a dedicated fpcInitializeRec()
    method that initializes the required fields. The reason is that this
    initialization is performed for out-parameters, and the fpcDeepCopy()
    method (used to copy one instance over another) has an out-parameter
    -> infinite loop

git-svn-id: branches/jvmbackend@18674 -
2011-08-20 08:23:27 +00:00
Jonas Maebe
40cf2cefa0 * when the user calls initialize(), force initialization to happen on the
JVM platform (normally it's not necessary because all types are
    automatically initialized)

git-svn-id: branches/jvmbackend@18672 -
2011-08-20 08:23:16 +00:00
Jonas Maebe
d0663411a5 * fixed order of operands on the jvm stack in case of a setlength(x,0) call
for a static field

git-svn-id: branches/jvmbackend@18671 -
2011-08-20 08:23:10 +00:00
Jonas Maebe
7286e3b645 * when determining the type to use for checkcast, first always dereference
pointers to implicit pointer types so that afterwards we can set the
    appropriate corresponding class type

git-svn-id: branches/jvmbackend@18668 -
2011-08-20 08:22:52 +00:00
Jonas Maebe
6cced31157 * treat conversions involving arrays of sets also as pointer conversions
git-svn-id: branches/jvmbackend@18667 -
2011-08-20 08:22:47 +00:00
Jonas Maebe
94be1980b4 * fixed type conversions between signed and unsigned ordinals of the same
size when stored in memory

git-svn-id: branches/jvmbackend@18666 -
2011-08-20 08:22:42 +00:00
Jonas Maebe
37aa2d8443 + full support for sets on the JVM target
o sets of enums are handled as JUEnumSet instances, others as JUBitSet
     derivatives (both smallsets and varsets, to make interoperability with
     Java easier)
   o special handling of set constants: these have to be constructed at run
     time. In case of constants in the code, create an internal constsym to
     represent them. These and regular constsyms are then aliased by an
     another internal staticvarsym that is used to initialise them in the
     unit initialisation code.
   o until they are constructed at run time, set constants are encoded as
     constant Java strings (with the characters containing the set bits)
   o hlcgobj conversion of tcginnode.pass_generate_code() for the genjumps
     part (that's the only part of the generic code that's used by the JVM
     target)
   o as far as explicit typecasting support is concerned, currently the
     following ones are supported (both from/to setdefs): ordinal types,
     enums, any other set types (whose size is the same on native targets)
   o enum setdefs also emit signatures
   o overloading routines for different ordinal set types, or for different
     enum set types, is not supported on the JVM target

git-svn-id: branches/jvmbackend@18662 -
2011-08-20 08:22:22 +00:00
Jonas Maebe
67a142c56e * fixed dereferencing pointers to JVM implicit pointer types in case the
pointer was in a register (has to be put into memory, because otherwise
    the compiler thinks that the entire type is stored in a register instead
    of only its address)

git-svn-id: branches/jvmbackend@18659 -
2011-08-20 08:22:05 +00:00
Jonas Maebe
956d63da9e * only treat Java interfaces and classes as equivalent to classdefs rather
than any objectdef

git-svn-id: branches/jvmbackend@18656 -
2011-08-20 08:21:49 +00:00
Jonas Maebe
625f52b7e4 * make sure that int->int conversions are handled by the generic code
* handle class->interface conversions by JVM-specific code

git-svn-id: branches/jvmbackend@18655 -
2011-08-20 08:21:44 +00:00
Jonas Maebe
67ce687683 * don't keep the original location in case of 2->4 byte ordinal type
conversions because the sign may not be correct in case the value comes
    from Java code

git-svn-id: branches/jvmbackend@18654 -
2011-08-20 08:21:39 +00:00