Commit Graph

260 Commits

Author SHA1 Message Date
Jonas Maebe
060e3ed4ee * changes from r21697, 21707, 21843, 21861, 21701, 21887, 21899 and 21900
to systemh.inc/system.inc/compproc.inc 'merged' into as of yet still
    JVM-specific copies of those files

git-svn-id: trunk@22125 -
2012-08-19 13:51:15 +00:00
Jonas Maebe
504544e173 * fixed null-termination in StringToWideChar() if the buffer is larger than
the string (mantis #22669)

git-svn-id: trunk@22124 -
2012-08-19 13:48:02 +00:00
tom_at_work
f252fd369e Tried to reorganize the ARM define mess in rtl/arm/arm.inc. Instead of requiring to enumerate all possible ARM variants each time a CPU feature is used, add a define of the format CPUARM_HAS_XXX and use that. Note that a better solution would be to properly implement the compiler cpuinfo infrastructure, however that is much more work.
+ CPUARM_HAS_BX is defined if the CPU supports the BX* instruction
  + CPUARM_HAS_REV is defined if the CPU supports the REV instruction. Note that you still have to check for compiler versions > 2.6.0 since the assembler reader of 2.6.0 does not understand that instruction.
  + CPUARM_HAS_IDIV is defined if the CPU supports the sdiv, udiv instructions. Use of this fixes a bug where previously these instruction were only used for armv7-m, while cortex3m cpus also support it.
  + CPUARM_HAS_LDREX is defined if the CPU supports the ldrex/strex instructions. Use of this fixes a bug with armv7(-a) cpus where this path has not been used.
  + SYSTEM_HAS_KUSER_CMPXCHG is defined if the system (mainly OS) support the kuser_cmpxchg functions. Use of this fixes a bug where ARMHF systems did not use it for synchronization (although ARMHF is armv7+ only, i.e. the LDREX path is used anyway)

git-svn-id: trunk@22081 -
2012-08-14 19:45:03 +00:00
tom_at_work
810adb2f65 Merge with trunk r22040. Regenerated makefiles.
git-svn-id: branches/targetandroid@22046 -
2012-08-09 08:12:34 +00:00
Jonas Maebe
56fcc87cb2 * add get_frame as an internal symbol for the jvm target because that target
defines INTERNAL_BACKTRACE (which assumes get_frame to be internal rather
    than a system unit procedure)
  * changed fpc_assert() declaration for jvm to be the same as for other
    targets, so the same code can be used to call it in ninl now that's
    called from the first pass

git-svn-id: trunk@21903 -
2012-07-12 13:25:02 +00:00
Jonas Maebe
596d359e02 * use current code page when converting ansichar to unicodestring
git-svn-id: trunk@21877 -
2012-07-11 15:22:31 +00:00
Jonas Maebe
aba6923187 * moved g_test_self() from cgobj to hlcgobj
git-svn-id: trunk@21861 -
2012-07-11 08:25:51 +00:00
Jonas Maebe
595f28e6fa + AnsistringClass.Create(unicodestring) constructor that implicitly selects
the DefaultSystemCodePage for use from Java code

git-svn-id: trunk@21724 -
2012-06-27 16:13:47 +00:00
pierre
8469741700 + Added additional addr pointer parameter to
get_caller_frame, get_caller_addr and dump_stack
  with default NIL value to systemh.inc.
  + Added new get_addr function.
  system.inc: Use get_addr and get_frame to call
  HandleErrorAddrFrame instead of HandleErrorFrame
  in several error functions.
  Modify dump_stack to use frame and addr parameters.
  Provide a dummy get_addr function returning nil.
  i386/i386.inc, x86_64./x86_64.inc: Provide real
  implementation of get_addr function.

git-svn-id: trunk@21697 -
2012-06-24 21:22:09 +00:00
Jonas Maebe
7a0ae38700 + also specify the parameter def when allocating a parameter via
getintparaloc + adapted all call sites of getintparaloc. This
    led to a number of additional, related changes:
   o corrected the type information for some getintparaloc parameters
   o don't allocate some intparalocs in cases they aren't used
   o changed "const tvardata" parameter into "constref tvardata" for
     fpc_variant_copy_overwrite to make pass-by-reference semantics
     explicit
   o moved a number of routines that now have to call find_system_type()
     from cgobj to hlcgobj so that cgobj doesn't have to start depending
     on the symtable unit
   o added versions of the cpureg alloc/dealloc methods to hlcgobj that
     call through to their cgobj counter parts, so we can call save/restore
     the cpu registers before/after calling system helpers from hlcgobj
     (not implemented in hlcgobj itself, because all basic register
      allocator functionality is still part of cgobj/cgcpu)

git-svn-id: trunk@21696 -
2012-06-24 15:02:12 +00:00
masta
3d9d484bfd Remove redundant CPU-Check for FPC_HAS_INTERNAL_ABS_LONG
compiler/options.pas only defines FPC_HAS_INTERNAL_ABS_LONG for cpus
which support the intrinsic. No need to check again in the rtl.

git-svn-id: trunk@21677 -
2012-06-21 20:12:31 +00:00
pierre
212d04a69e * Avoid line longer than 255
git-svn-id: trunk@21600 -
2012-06-13 22:34:49 +00:00
Jonas Maebe
8234a842e6 * fixed conversion of empty ansistring/widestring constants to pchar on
the jvm target + test

git-svn-id: trunk@21391 -
2012-05-26 11:32:20 +00:00
Jonas Maebe
834026bfb5 * synchronised with trunk up to r21067
git-svn-id: branches/jvmbackend@21068 -
2012-04-26 21:24:20 +00:00
Jonas Maebe
0659058e44 * fixed ansistring -> pchar type conversion on JVM target now that empty
ansistrings are represented by nil
  * fixed type conversion of constant empty ansistring/unicodestring to
    pchar/pwidechar on the JVM target

git-svn-id: branches/jvmbackend@21055 -
2012-04-25 22:29:20 +00:00
Jonas Maebe
8e3d7fe8d3 * fixed genmultistringadd() optimization for jvm and enabled it
* created separate version of fpc_AnsiStr_Concat_multi() after all
    because it contains a punicodechar(unicodestring) typecast, which
    can't be supported on the JVM target (and splitting it out in the
    generic code seems like a bit overkill), and restored original
    generic version of fpc_AnsiStr_Concat_multi() (slightly faster
    than version partially adapted for jvm)

git-svn-id: branches/jvmbackend@20903 -
2012-04-16 20:51:51 +00:00
Jonas Maebe
1efee1d2eb * set destination codepage in widestringmanager.Unicode2AnsiMoveProc() like
on other platforms, rather than explicitly setting it afterwards
    everywhere

git-svn-id: branches/jvmbackend@20902 -
2012-04-16 20:51:46 +00:00
Jonas Maebe
aee5380ae0 * merged trunk up to r20882
o support for the new codepage-aware ansistrings in the jvm branch
   o empty ansistrings are now always represented by a nil pointer rather than
     by an empty string, because an empty string also has a code page which
     can confuse code (although this will make ansistrings harder to use
     in Java code)
   o more string helpers code shared between the general and jvm rtl
   o support for indexbyte/word in the jvm rtl (warning: first parameter
     is an open array rather than an untyped parameter there, so
     indexchar(pcharvar^,10,0) will be equivalent to
     indexchar[pcharvar^],10,0) there, which is different from what is
     intended; changing it to an untyped parameter wouldn't help though)
   o default() support is not yet complete
   o calling fpcres is currently broken due to limitations in
     sysutils.executeprocess() regarding handling unix quoting and
     the compiler using the same command lines for scripts and directly
     calling external programs
   o compiling the Java compiler currently requires adding ALLOW_WARNINGS=1
     to the make command line

git-svn-id: branches/jvmbackend@20887 -
2012-04-15 15:54:10 +00:00
Jonas Maebe
85ef5e109c + assert() support for the JVM target (currently ignores the Java classloader
assertionStatus setting)

git-svn-id: branches/jvmbackend@20388 -
2012-02-20 11:28:59 +00:00
Jonas Maebe
8b4b081ed5 * fixed fpc_tcon_shortint_array_from_string() in case the length of the array
to initialize was odd

git-svn-id: branches/jvmbackend@20210 -
2012-02-01 18:03:58 +00:00
Jonas Maebe
0d5b2b84a8 + Android/JVM target, including a translation of the Android r14 SDK
(= Android 4.0) java headers: java.*, javax.*, org.*, junit.*, android.*).
    The RTL can also be used to target earlier versions of the Android
    platform, but you manually have to take care of not using APIs that
    weren't available yet. Adding separate units for separate platform
    versions would only partly solve the problem, because some of the
    classes used inside the system unit have also changed across
    versions.

    Use -Tandroid while compiling to select the Android OS as target
    platform.

git-svn-id: branches/jvmbackend@19830 -
2011-12-12 02:34:34 +00:00
Jonas Maebe
0e65d01274 * renamed java-specific compproc.inc to jcompproc.inc to prevent timestamp
conflicts when the compiler finds inc/compproc.inc while compiling other
   units later on

git-svn-id: branches/jvmbackend@19828 -
2011-12-12 02:34:04 +00:00
Jonas Maebe
c9e6bc8d49 + support for building jvm-java compiler/rtl via top-level
make CPU_TARGET=jvm OS_TARGET=java all
    ("make install" does not yet fully work: the classes under
     rtl/units/jvm-java/org/freepascal/rtl aren't installed yet)

git-svn-id: branches/jvmbackend@19747 -
2011-12-04 15:33:55 +00:00
Jonas Maebe
74510f9069 + generic infrastructure for target-specific switches
+ -CTcompactintarrayinit command line option to change the code generation
    for typed array of some kind of integer-type initialization so that it
    takes up less space in the bytecode (because the bytecode for all
    routines, including the class initialization code that contains the
    typed constant init code, is limited 64kb, large array or multiple
    array constants could fairly easily bump into that limit)

git-svn-id: branches/jvmbackend@19638 -
2011-11-14 22:57:41 +00:00
Jonas Maebe
c42e4178c5 * fixed copy(unicodestring,x,y) with x<>1 (second parameter of
JLString.subString() is end index, not total length to copy)

git-svn-id: branches/jvmbackend@19618 -
2011-11-10 18:53:39 +00:00
Jonas Maebe
f96f5f9e94 + {$VARPARACOPYOUTCHECK+/-} / -Cv switch to enable checking
var-parameters on the JVM target for changes to the value passed
    as var-parameter during the function call (because they are handled
    via copy-in/copy-out, this may indicate unexpected bahviour later on).

    out-parameters are checked in the same way, except if the out-parameter
    is a local variable because then reading it before the call may result
    in a bytecode verification error (since the variable may not yet be
    initialized)

git-svn-id: branches/jvmbackend@19153 -
2011-09-19 19:59:26 +00:00
Jonas Maebe
fdab7122dd * catch JLRInvocationTargetException raised when using JLRMthod.invoke() to
call a procvar (includes virtual constructors and virtual class methods),
    and raise its getCause() so that the original exception is propagated to
    the caller

git-svn-id: branches/jvmbackend@19030 -
2011-09-08 15:03:55 +00:00
Jonas Maebe
ab7f0a4461 * changed the parameters of the fpc_pchar_ansistr_intern_charmove() added in
r18906 from byte into sizeint (copy/paste error from the similar shortstring
    helper, where both source and destination are shortstrings)

git-svn-id: branches/jvmbackend@18939 -
2011-09-01 18:27:06 +00:00
Jonas Maebe
816f9c20c7 * part of r18925, forgot to commit
git-svn-id: branches/jvmbackend@18926 -
2011-08-31 20:14:21 +00:00
Jonas Maebe
a4cf406189 * use generic string concatentation and comparison infrastructure for the
JVM target (and also the generic routines in case of shortstrings)

git-svn-id: branches/jvmbackend@18910 -
2011-08-29 22:59:25 +00:00
Jonas Maebe
5496436349 * the generic astrings.inc is now also used to the extent possible on
the JVM target, and pos/insert/delete/val/str/uniquestring/setstring/
    stringofchar/... are now also available for ansistrings on the JVM
    target

git-svn-id: branches/jvmbackend@18906 -
2011-08-29 22:59:03 +00:00
Jonas Maebe
7c56dbee12 * make sure that when making an ansistring shorter using setlength(),
it remains null-terminated

git-svn-id: branches/jvmbackend@18883 -
2011-08-28 19:22:29 +00:00
Jonas Maebe
3a423b331c * full implementation of all routines in rtl/inc/ustringh.inc (except for
val/str for enums for now) for the JVM target: insert/delete/pos/...
  * use generic unicodestring helper routines where possible for the JVM
    target (not that many as for shortstrings since unicodestring is
    handled using java.lang.String)
  + complete widestring manager implementation for the JVM target. It uses
    a class with virtual methods rather than a record with function pointers
    for speed reasons though (since no existing widestring manager will be
    compatible anyway, that shouldn't cause any problems)

git-svn-id: branches/jvmbackend@18882 -
2011-08-28 19:22:22 +00:00
Jonas Maebe
1f96763b9d * renamed Java-specific sstrings.inc/sstringh.inc to jsstrings.inc/
jsstringh.inc -> use generic inc/sstrings.inc
  * added a bunch of extra {$ifdef FPC_HAS_XXX} protections around
    routines in inc/sstrings.inc and implemented those routines for
    the JVM target in java/jsstrings.inc
  * use the majority of the generic routine in sstrings.inc now also
    for the JVM target! Only a few changes were needed:
   o in a few places, calls to move() for copying shortstring->shortstring
     or shortstring->chararray were replaced with calls to a new inline
     helper that calls move() in the version in inc/sstrings.inc, and
     JLSystem.arraycopt() in in the version in java/jsstrings.inc
   o changed the currency argument to str() for the JVM target to constref
     so its address can be taken (has to be typecasted to int64 without
     changing the value), and similarly changed the temporary result
     inside that routine to an array of 1 elements so the address can be
     taken
   o don't typecast the real value to a record type in str_real for the
     JVM target, but work via an int64 instead to extract sign/mantissa/exp
   o everything else compiled and worked as is!!
  -> val, str, hexstr/octstr/binstr, delete, pos, insert, setstring and
     comparetext now all work for shortstrings on the JVM target

git-svn-id: branches/jvmbackend@18836 -
2011-08-24 22:11:43 +00:00
Jonas Maebe
56e724cea6 * moved general system includes accidentally put in jdynarr.inc to
system.pp

git-svn-id: branches/jvmbackend@18835 -
2011-08-24 22:11:36 +00:00
Jonas Maebe
eb268fb2c4 + tcallnode.createinternmethodres() that allows specifying a forced
resultdef for internally generated method calls
  * force the resulttype of methods used to build non-unicode string
    constants on the JVM platform to the stringconstn's resultdef

git-svn-id: branches/jvmbackend@18832 -
2011-08-24 22:11:16 +00:00
Jonas Maebe
77e913f60f + a bunch of fillchar implementations for different kinds of arrays
git-svn-id: branches/jvmbackend@18830 -
2011-08-24 22:10:59 +00:00
Jonas Maebe
04478c5f33 * enabled overloads that were disabled on the JVM target because of
signature conflicts by declaring them as "external", so that they
    map to exactly that routine they would normally conflict with

git-svn-id: branches/jvmbackend@18824 -
2011-08-23 22:02:37 +00:00
Jonas Maebe
336420ef46 * only make clone method accessible once if needed
git-svn-id: branches/jvmbackend@18821 -
2011-08-23 20:30:20 +00:00
Jonas Maebe
a2a0436347 + support for threadvars in the JVM based on JLThreadLocal; see
rtl/java/jtvarh.inc for the details

git-svn-id: branches/jvmbackend@18820 -
2011-08-23 17:45:01 +00:00
Jonas Maebe
72d6d9ac97 * moved JLRField from jdk15 to the system unit
* fixed FpcBaseProcVarType.clone: create a new method field "pointer" and
    set it (using the java.lang.reflect interface). Previously, the pointer
    to the method record was copied via the inherited clone, which meant
    that the original and new procvar shared it

git-svn-id: branches/jvmbackend@18816 -
2011-08-23 16:07:13 +00:00
Jonas Maebe
79e971ea12 * fixed fpc_dynarr_copy() for making copies of arrays of implicit pointer
types (the elements have to be cloned)

git-svn-id: branches/jvmbackend@18810 -
2011-08-23 15:25:42 +00:00
Jonas Maebe
44f074ebaa * mark FpcBitSet as implementing JLCloneable so it can be cloned,
and add clone() method that calls inherited clone so that in case
    of reflection lookup it will be found in this class rather than
    getting an exception and having to search the parent class (will
    be used in threadvar implementation)

git-svn-id: branches/jvmbackend@18809 -
2011-08-23 15:25:35 +00:00
Jonas Maebe
28c20cfc5e * the default string type for the JVM target is no longer automatically
unicodestring = java.lang.String. The reason this was the default in
    the past is that this was the first string type that was implemented,
    and without it being the default most code involving string operations
    would fail. Now the default strings types are the same as for other
    targets
  + new {$modeswitch unicodestrings} directive, that when activated
    *together* with {$h+},
   1) changes char into an alias for widechar
   2) changes string into an alias for unicodestring
   3) changes the preferred string evaluation type (in case of uncertainty)
      to unicodestring
    {$modeswitch unicodestrings} with {$h-} does not change anything at all
    regarding the string type (it still changes the char type)
  + new uuchar unit that redefines char as widechar, and which is automatically
    included by the compiler if {$modeswitch unicodestrings} is enabled

git-svn-id: branches/jvmbackend@18781 -
2011-08-20 08:35:47 +00:00
Jonas Maebe
144ba2a2ad * enabled (generic) fpc_pchar_length() and fpc_pwidechar_length()
git-svn-id: branches/jvmbackend@18771 -
2011-08-20 08:34:31 +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
27f2edea57 + pchar -> short/ansi/unicodestring support
git-svn-id: branches/jvmbackend@18767 -
2011-08-20 08:34:11 +00:00
Jonas Maebe
1ff004312b * null-terminate ansistrings like on native platforms (so support
can be added to typecast them to pchars)
  * fixed array-of-char to ansistring conversion in case of zero-based
    array and an embedded #0 (didn't stop at the embedded #0)

git-svn-id: branches/jvmbackend@18766 -
2011-08-20 08:34:05 +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
549e51fdfa * uncommented a bunch of pointer types
git-svn-id: branches/jvmbackend@18764 -
2011-08-20 08:33:54 +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
6d0dd347ba * declare procvar constructors as "overload" so that the implicitly added
parameterless constructor can also be found from Delphi mode

git-svn-id: branches/jvmbackend@18758 -
2011-08-20 08:33:24 +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
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
8a95a04e16 * extracted dynarray helpers from system unit into jdynarr.inc (were
in the system unit for easier debugging)
  * disabled a bunch more feature flags by default for the JVM target
  * incorporate modified version of inc/systemh.inc (split into two parts:
    jsystemh_types.inc and jsystemh.inc, because some of the types are
    required for the declaration of the shortstring/ansistring/set/...
    classes, which in turn are required for the routine declarations) and
    inc/system.inc (as jsystem.inc)
   o moved some routines around from old to new locations based on where
     they appear in the common files
   o added a number of defines that allow skipping more common implementations
     in case a platform-specific one is already available
  * all base classes (AnsistringClass etc) are now descendants of
    JLObject rather than TObject, because their declaration is now parsed
    before TObject is known (and there's no need for them to inherit from
    TObject)
  * incorporate modified version of inc/system.inc
  * use the common version of generic.inc, currh.inc, gencurr.inc and
    genmath.inc (with small modification to those files)
  + addition of quite a bit of system unit functionality (halt, runerror,
    random, round, str() for integer types, abs, odd, endian swapping helpers,
    bit scanning, trigonometric functions, ln, exp, ...)
   o round()/trunc() for comp-types has been renamed trunc_comp() on the
     JVM target because their JVM signature conflicts with trunc(currency)
   o the unsigned versions of swapendian() and other endian helpers are not
     available on the JVM target because of JVM signature conflicts

git-svn-id: branches/jvmbackend@18746 -
2011-08-20 08:32:13 +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
441787672d * migrated java.lang.NoSuchMethodException to java_sys.inc
* catch java.lang.NoSuchMethodException exceptions when resolving a procvar,
    because java.lang.Class.getDeclaredMethod() only searches that particular
    class itself and not its parents -> in case we get the address of a method
    that's not overridden in the current class, also search the parent classes

git-svn-id: branches/jvmbackend@18730 -
2011-08-20 08:28:45 +00:00
Jonas Maebe
b59df3f2fd * reparsed with new version of javapp that doesn't mark final static
methods as "virtual" anymore (since they're not virtual, and the
    compiler now handles virtual class methods differently)

git-svn-id: branches/jvmbackend@18725 -
2011-08-20 08:27:59 +00:00
Jonas Maebe
7092f2957a * use deep copies rather than cloning when copying array contents
(since the elements in the destination array are guaranteed to
     exist already)

git-svn-id: branches/jvmbackend@18719 -
2011-08-20 08:27:27 +00:00
Jonas Maebe
3ac950eed7 * changed the parameter of fpcDeepCopy() from an out-parameter of the
actual recordtype into FpcBaseRecordType so we can also use
    the deep copy routine in the RTL
  + added abstract fpcDeepCopy() declaration to FpcBaseRecordType class

git-svn-id: branches/jvmbackend@18718 -
2011-08-20 08:27:22 +00:00
Jonas Maebe
469bda2710 * fixed ShortStringClass.toString() (skipped last char) and also use it
in ShortStringClass.toUnicodeString()

git-svn-id: branches/jvmbackend@18717 -
2011-08-20 08:27:16 +00:00
Jonas Maebe
1ac7146182 * synchronised code of fpc_ansistr_to_chararray() with
fpc_shortstr_to_chararray()
  * same for fpc_unicodestr_to_chararray() + fixes

git-svn-id: branches/jvmbackend@18702 -
2011-08-20 08:26:00 +00:00
Jonas Maebe
02f443ce68 * support source/destinationshortstrings of different length in
ShortStringClass.FpcDeepCopy (can happen when copying value
    parameters like string[4] into local storage in case a string
    longer than 4 characters was passed)
  * create chararray of the correct maximum length when constructing
    a chararray from a constant string
  * don't pass invalid ranges to JLArrays.fill() when padding a
    chararray after filling it using the contents of shortstring

git-svn-id: branches/jvmbackend@18701 -
2011-08-20 08:25:54 +00:00
Jonas Maebe
5a1bca3b75 * small optimization
git-svn-id: branches/jvmbackend@18700 -
2011-08-20 08:25:49 +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
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
4e0ffdebfd * FPCJDynArrTypeEnumSet/FPCJDynArrTypeBitSet support in fpc_dynarray_copy()
git-svn-id: branches/jvmbackend@18683 -
2011-08-20 08:24:20 +00:00
Jonas Maebe
34bfe0bbfd * reparsed with varags -> const open array change
git-svn-id: branches/jvmbackend@18679 -
2011-08-20 08:23:56 +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
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
5ea497857d + FpcEnumValueObtainable interface that's implemented by all FPC
enums (for use in set factory helpers)

git-svn-id: branches/jvmbackend@18651 -
2011-08-20 08:21:24 +00:00
Jonas Maebe
815ab863b6 * fixed external name for inner classes (must not contain the name for
the outer class)
  * migrated some types that will be required for set support from jdk15
    to java_sys

git-svn-id: branches/jvmbackend@18627 -
2011-08-20 08:16:30 +00:00
Jonas Maebe
13b0ac91d9 + generate java.lang.Enum descendant classes for Pascal enum types
o these classes get an "enum" flag in the class files
   o these classes get a class field (whose type is that same enum
     class) per enum in the type, which also gets the "enum" flag
   o those class fields are initialised in the class constructor
     with the name of the enum and their order in the declaration
   o if the enum has jumps in FPC (lowest value is not 0, or not
     all values are contiguous), then we add an extra field
     to hold the FPC ordinal value of the enum
   o these classes get a class field valled $VALUES that contains
     a reference to the aforementioned class fields in order of
     declaration (= ordinal->instance mapping, JDK-mandated)
   o apart from the JDK-mandated instance methods (values, valueOf),
     also add FPCOrdinal (returns FPC ordinal value; same as order
     of declaration in case of no jumps) instance method and FPCValueOf
     (returns enum corresponding to FPC ordinal value) static class
     method
   o the mapping between FPC ordinals and enum instances in case of
     jumps is stored in a hashmap whose size is the next prime number
     greater or equal than the number of enum elements
   o moved several extra JDK types to the system unit for the enum
     support, and for future boxing and Java set support
   o several new synthetic method identifiers to generate the enum class
     methods/constructor/class constructor
   o enums with jumps are ordered by FPC ordinal value in the JVM
     $VALUES array so that the java.lang.Enum.doCompare() method
     will properly compare them

git-svn-id: branches/jvmbackend@18616 -
2011-08-20 08:15:28 +00:00
Jonas Maebe
0706cb5eb6 + support for pointers to types that are implicit pointer types in the JVM
(non-dynamic arrays, records, shortstrings)
  - removed the ability to typecast such types directly into related class
    types, you have to use the @-operator first now to get a pointer to
    the type
   o updated the RTL and internal compiler code to properly use this
     new convention
   o allowed removing several special cases from
     tjvmtypeconvnode.target_specific_general_typeconv(), and that
     method can probably be removed completely over time
  * no longer give compile time errors for pointer-related typecasts that
    will fail at run time, because the checking was too complex and could
    be worked around via actual pointer typecasts anyway
  * removed some unnecessary checkcast operations (for shortstring/
    shortstringclass)

git-svn-id: branches/jvmbackend@18574 -
2011-08-20 08:11:49 +00:00
Jonas Maebe
6857dde33e + shortstring support for the JVM target (including accessing character 0 as
the "length byte")

git-svn-id: branches/jvmbackend@18570 -
2011-08-20 08:11:28 +00:00
Jonas Maebe
f2d3203bb6 * commented out unimplemented pos() variant
git-svn-id: branches/jvmbackend@18569 -
2011-08-20 08:11:22 +00:00
Jonas Maebe
13cf0e031e * removed unused variables
* char -> ansichar

git-svn-id: branches/jvmbackend@18568 -
2011-08-20 08:11:17 +00:00
Jonas Maebe
87f812c778 * fixed typo in comment
git-svn-id: branches/jvmbackend@18567 -
2011-08-20 08:11:12 +00:00
Jonas Maebe
db1d22aeae * fixed header comments
git-svn-id: branches/jvmbackend@18566 -
2011-08-20 08:11:08 +00:00
Jonas Maebe
baad29373e + ansistr_to_shortstr and vice versa stub helpers
git-svn-id: branches/jvmbackend@18564 -
2011-08-20 08:10:54 +00:00
Jonas Maebe
446d91eaab + ansistring support. Items of note:
o support for ansistring constants. It's done via a detour because the
      JVM only supports UTF-16 string constants (no array of byte or anything
      like that): store every ansicharacter in the lower 8 bits of an
      UTF-16 constant string, and at run time copy the characters to an
      ansistring. The alternative is to generate code that stores every
      character separately to an array.
    o the base ansistring support is implemented in a class called
      AnsistringClass, and an ansistring is simply an instance of this
      class under the hood
    o the compiler currently does generate nil pointers as empty
      ansistrings unlike for unicodestrings, where we always
      explicitly generate an empty string. The reason is that
      unicodestrings are the same as JLString and hence common
      for Java interoperation, while ansistrings are unlikely to
      be used in interaction with external Java code

  * fixed indentation

git-svn-id: branches/jvmbackend@18562 -
2011-08-20 08:10:39 +00:00
Jonas Maebe
b60e50b2b0 - reverted 679f3968901f0d565644d59e046eb25d5402f027, because it requires
support for concat_multi for ansistrings to prevent compilation
    problems there

git-svn-id: branches/jvmbackend@18545 -
2011-08-20 08:09:10 +00:00
Jonas Maebe
278a581666 + jdk15 unit with jdk 1.5 header translation
git-svn-id: branches/jvmbackend@18537 -
2011-08-20 08:08:21 +00:00
Jonas Maebe
e403ddca0c * enabled generic multi-string concatenation optimization now that var
parameters for strings work (although they're not as efficient as
    function results for the JVM target)

git-svn-id: branches/jvmbackend@18535 -
2011-08-20 08:08:05 +00:00
Jonas Maebe
845f50448c + support for qword div/mod via helper (the JVM only supports signed
64 bit division natively)

git-svn-id: branches/jvmbackend@18523 -
2011-08-20 08:07:02 +00:00
Jonas Maebe
7a5d334951 + support for copy(dynarray)
git-svn-id: branches/jvmbackend@18504 -
2011-08-20 08:05:23 +00:00
Jonas Maebe
ecba07c6a8 * greatly simplified dynamic array handling by making use of the
java.lang.reflect functionality

git-svn-id: branches/jvmbackend@18503 -
2011-08-20 08:05:17 +00:00
Jonas Maebe
6c35ea202b + added several reflection classes for use in array processing
git-svn-id: branches/jvmbackend@18502 -
2011-08-20 08:05:12 +00:00
Jonas Maebe
49de6346ce * replaced manual array copy loops with calls to JLSystem.arraycopy(); still
separate helper per array element type because there is no generic array
    type, and we need to get the length of the arrays

git-svn-id: branches/jvmbackend@18501 -
2011-08-20 08:05:07 +00:00
Jonas Maebe
c75246706d + stubbed ansistring support (using ansistrings compiles, but does not
generate working code)

git-svn-id: branches/jvmbackend@18499 -
2011-08-20 08:04:57 +00:00
Jonas Maebe
d1a1d30e04 * unless compiled with -dnounsupported, the compiler will now accept not
only JVM constructs that are already implemented, but also ones that
    will be supported in the future but that aren't implemented yet (to
    make it easier to already adapt code to the future changes)

git-svn-id: branches/jvmbackend@18498 -
2011-08-20 08:04:51 +00:00
Jonas Maebe
4c0849a592 * fixed fpc_unicodestr_compare_equal (has to return 0 in case of
equality, not 1)

git-svn-id: branches/jvmbackend@18490 -
2011-08-20 08:04:11 +00:00
Jonas Maebe
91855becfe + unicodestring support for the JVM target (except for multiple adds
in a single statement, to be added later)
   o the unicodestrings are internally simply java.lang.String instances
   o at the language level, the unicodestrings are assignment-compatible
     with java.lang.String
   o constant strings can be implicitly converted to java.lang.String
   o since java.lang.String is immutable, in particular changing a
     single character in a string is extremely inefficient. This could
     be solved by letting unicodestring map to java.lang.StringBuilder,
     but that would make integration with plain Java code harder

git-svn-id: branches/jvmbackend@18470 -
2011-08-20 08:02:33 +00:00
Jonas Maebe
d759598c70 * set the namespace of the system unit to org.freepascal.rtl
git-svn-id: branches/jvmbackend@18469 -
2011-08-20 08:02:27 +00:00
Jonas Maebe
03af03e696 * changed TObject from an alias for JLObject into a derived class from
JLObject with the method "Free" and a virtual destructor "Destroy"
    (and Free is automatically called from the "finalize" method,
     which in turn is called by the JVM when the instance is collected;
     note that there is no final collection before the JVM shuts down,
     so it may never be called if you don't call Free explicitly yourself)
  * if you don't specify an explicit ancestor for a Java class, set
    the parent to TObject instead of to JLObject (for better compatibility
    with regular Pascal code)

git-svn-id: branches/jvmbackend@18466 -
2011-08-20 08:02:12 +00:00
Jonas Maebe
40e0b4677a + support for (only named, for now) records in the JVM target:
implemented via classes, all descending from system.FpcBaseRecordType
    (records are also considered to be "related" to system.FpcBaseRecordType
     on the JVM target)
  * several routines are auto-generated for all record-classes: apart
    from a default constructor (if there is none), also clone (which
    returns a new instance containing a deep copy of the current
    instance) and deepCopy (which copies all fields of one instance
    into another one)
   o added new field "synthetickind" to tprocdef that indicates what
     kind of synthetically generated method it is (if any), and
     mark such methods also as "synthetic" in the JVM assembler code
   o split off the JVM-specific parser code (e.g., to add default
     constructors) into pjvm.pas

git-svn-id: branches/jvmbackend@18450 -
2011-08-20 08:00:50 +00:00
Jonas Maebe
698deb08c5 * parsed with latest version, adds "virtual" modifiers
git-svn-id: branches/jvmbackend@18441 -
2011-08-20 07:59:49 +00:00
Jonas Maebe
60e0347bd9 * replaced partial manual declarations of some Java classes with
automatically generated full declarations by javapp, using the
    command line parameters:
    -protected java.lang.System java.lang.Object java.io.Serializable java.lang.Float java.lang.Double java.lang.String java.lang.StringBuilder java.lang.StringBuffer java.lang.CharSequence java.lang.AbstractStringBuilder java.lang.Appendable java.lang.Number java.lang.IndexOutOfBoundsException java.lang.RuntimeException java.lang.IllegalArgumentException java.lang.Exception java.lang.Throwable java.lang.LinkageError java.lang.Error java.lang.Comparable java.lang.Character java.text.Collator java.lang.Cloneable java.util.Comparator -i -o java_sys

git-svn-id: branches/jvmbackend@18422 -
2011-08-20 07:58:20 +00:00
Jonas Maebe
5abf6d0aa4 + thlcgobj support of the managed open array initialization fixes of
svn r17068,17071,17081,17136
  * changed all init_paras code in both thlcgobj and ncgutil to use
    location_get_data_ref() instead of direct a_load_loc_reg()/
    ref.base:=reg so it also works with the JVM target
  * changed all init_paras code so it works with targets that do
    not pass an implicit high parameter for open array (and a similar
    fix in ncgcal)
  + added support for initializing array (both regular and open)
    "out" parameters of reference counted types on the JVM target
    (the arrays will be initialised with nil rather than an empty
     array for implementation reasons, see comments in compproc.inc)
  * factored out calling of functions in the system unit directly
    from hlcgobj

git-svn-id: branches/jvmbackend@18421 -
2011-08-20 07:58:14 +00:00
Jonas Maebe
33ad6e4637 + 1/2/3-dimensional array types of the base types for use by the headers
generated by javapp

git-svn-id: branches/jvmbackend@18407 -
2011-08-20 07:57:08 +00:00
Jonas Maebe
2c313e397e + support for regular arrays and open arrays
o support for copying value parameters at the callee side if they were
     passed by reference in hlcg
   o JVM g_concatcopy() implementation for arrays
   o moved code to get length of an array from njvminl to hlcgcpu so it can
     be reused elsewhere as well
   o export array copy helpers from system unit for use when assigning one
     array to another
   o some generic support for types that are normally not implicit pointers,
     but which are for the JVM target (such as normal arrays)
  * handle assigning nil to a dynamic array by generating a setlength(x,0)
    node instead of by hardcoding a call to fpc_dynarray_clear, so
    target-specific code can handle it if required
  * hook up gethltemp() for JVM ttgjvm so array temps are properly
    allocated

git-svn-id: branches/jvmbackend@18388 -
2011-08-20 07:55:27 +00:00
Jonas Maebe
0a3a62811b + try/except and try/finally support for JVM target:
o always create exceptvarsym entry for on-nodes (on all targets) to remove
     some special cases when an unnamed exception was caught
   o the JVM tryfinally node generates the finally code twice: once for the
     case where no exception occurs, and once when it does occur. The reason
     is that the JVM's static bytecode verification otherwise cannot prove
     that we will only reraise the caught exception when we caught one in
     the first place (the old "jsr" opcode to de-duplicate finally code
     is no longer used in JDK 1.6 because it suffered from the same problem,
     see Sun Java bug
     http://webcache.googleusercontent.com/search?q=cache:ZJFtvxuyhfMJ:bugs.sun.com/bugdatabase/view_bug.do%3Fbug_id%3D6491544 )

git-svn-id: branches/jvmbackend@18387 -
2011-08-20 07:55:21 +00:00
Jonas Maebe
9a3714ce42 * changed identifier of system unit from "System" into "system" to prevent name
clash with Java's "System" (from e.g. System.out.println())

git-svn-id: branches/jvmbackend@18386 -
2011-08-20 07:55:15 +00:00
Jonas Maebe
ee8b662fa1 + dynamic array support for the JVM target: setlength(), length(), high():
o since the JVM does not support call-by-reference, setlength() works
     by taking an argument pointing to the old array and one to the new
     array (the latter is always created in advance on the caller side,
     even if not strictly required, because we cannot easily create it
     on the callee side in an efficient way). Then we copy parts of the
     old array to the new array as necessary
   o to represent creating a new dynamic array, the JVM target uses
     an in_new_x tinlinenode
  + tasnode support for the JVM. Special: it can also be used to convert
    java.lang.Object to dynamic arrays, and dynamic arrays of java.lang.Object
    to dynamic arrays with more dimensions (arrays are special JVM objects,
    and such support is required for the setlength support)
  + check whether explicit type conversions are valid, and if so, add the
    necessary conversion code since we cannot simply reinterpret bit patterns
    in most cases in the JVM:
   o in case of class and/or dynamic array types, convert to an as-node
   o in case of int-to-float or float-to-int, use java.lang.Float/Double
     helpers (+ added the definitions of these helpers to the system unit)

git-svn-id: branches/jvmbackend@18378 -
2011-08-20 07:54:17 +00:00
Jonas Maebe
34674eee5e * pred(length(dynarr)) -> high(dynarr)
git-svn-id: branches/jvmbackend@18371 -
2011-08-20 07:53:14 +00:00
Jonas Maebe
ca98c329b3 + (dynamic) array helper routines
git-svn-id: branches/jvmbackend@18357 -
2011-08-20 07:51:19 +00:00
Jonas Maebe
0dc5baa681 * regenerated so it doesn't set an -XP parameter by default
git-svn-id: branches/jvmbackend@18351 -
2011-08-20 07:50:24 +00:00
Jonas Maebe
505660262d + sqr(float) and trunc() support
git-svn-id: branches/jvmbackend@18342 -
2011-08-20 07:48:47 +00:00
Jonas Maebe
817ebe5d8d + aliases for Java primitive types (jbyte, jshort, jint, jlong, jchar,
jsingle, jdouble, jboolean)

git-svn-id: branches/jvmbackend@18321 -
2011-08-20 07:45:39 +00:00
Jonas Maebe
d840d99231 + minimal Java rtl (based on embedded rtl, but with all code and most
declarations removed)

git-svn-id: branches/jvmbackend@18320 -
2011-08-20 07:45:34 +00:00