Commit Graph

88 Commits

Author SHA1 Message Date
Jonas Maebe
77707a447e * fixed fake ansistring length() support
git-svn-id: branches/jvmbackend@18514 -
2011-08-20 08:06:14 +00:00
Jonas Maebe
80a63197e3 + support for unaryminus for the JVM target (integer via generic code, float
JVM-specific code)

git-svn-id: branches/jvmbackend@18512 -
2011-08-20 08:06:05 +00:00
Jonas Maebe
f764a72d85 * fixed evaluation stack height count for OP_NEG and non-64 bit opertions
git-svn-id: branches/jvmbackend@18511 -
2011-08-20 08:06:00 +00:00
Jonas Maebe
694ccf3df3 + dummy support for untyped var/const/out parameters on the JVM target
o includes basic "auto-boxing" infrastructure to support Delphi.NET-
     compatible untyped parameters as described at
     http://hallvards.blogspot.com/2007/10/dn4dp24-net-vs-win32-untyped-parameters.html

git-svn-id: branches/jvmbackend@18510 -
2011-08-20 08:05:54 +00:00
Jonas Maebe
3259eae110 * fixed typecasting checks from/to arrays of records
git-svn-id: branches/jvmbackend@18508 -
2011-08-20 08:05:43 +00:00
Jonas Maebe
739c654e3a + support for main programs for the JVM target
o moved several routines from pmodules to ngenutil and overrode them
     in njvmutil (for unit initialisation tables, resource strings, ...)
   o force the evaluation stack size to at least 1 for the main program,
     because the unit initialisation triggers are inserted there afterwards
     and they require one stack slot

git-svn-id: branches/jvmbackend@18507 -
2011-08-20 08:05:38 +00:00
Jonas Maebe
e775e2d9ae * moved gen_entry_code/gen_exit_code from ncgutil to hlcgobj,
and overrode both with empty stubs for the JVM

git-svn-id: branches/jvmbackend@18506 -
2011-08-20 08:05:33 +00:00
Jonas Maebe
f20e347c7e * dummy support for copying arrays of variant/set
git-svn-id: branches/jvmbackend@18505 -
2011-08-20 08:05:28 +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
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
4491dafd48 * exit once we've found a target-specific handler for a type
conversion node so later checks won't try to further convert it

git-svn-id: branches/jvmbackend@18497 -
2011-08-20 08:04:45 +00:00
Jonas Maebe
a729201e37 * map normal sets to R_ADDRESSREGISTER
git-svn-id: branches/jvmbackend@18496 -
2011-08-20 08:04:40 +00:00
Jonas Maebe
99177a75fb * tprocdef -> tabstractprocdef typecasts so the code will also work
when calling procvars is supported

git-svn-id: branches/jvmbackend@18495 -
2011-08-20 08:04:35 +00:00
Jonas Maebe
8649788b7f * typecast the argument and result type of the setlength() helper to
the types as declared in the system unit, since they can also be
    used with equivalent but different types (e.g., byte vs shortint)

git-svn-id: branches/jvmbackend@18487 -
2011-08-20 08:03:56 +00:00
Jonas Maebe
5b915178fa + support for deep copy of array of strings
git-svn-id: branches/jvmbackend@18477 -
2011-08-20 08:03:09 +00:00
Jonas Maebe
43c5ed20c2 + support for initialising typed constants via compiler-generated
assignment-nodes. For global typed constants and typed constants/
    local variable initialisers in regular functions/procedurs, the
    assignments are performed in the unit initialisation code. For
    those in object/record definitions and their methods, it's done
    in the class constructor. Since we may not yet have parsed all
    method implementations when the class constructor is parsed, part
    of these may be initialised in a helper routine called from the
    class constructor. The ones known when the class constructor is
    parsed are inited there, because the ones marked as "final" and
    declared as static class fields must be initialised in the class
    constructor for Java
   o new set systems_typed_constants_node_init in systems unit that
     indicates that a target uses node trees to initialise typed consts
     instead of an initialised data section
   o mark typed constants in {$j-} mode as "final" for JVM
   o mangle the name of staticvarsyms inside localtables a bit to avoid
     name clashes (only with procedure names for now, no parameters yet
     so can still cause problems with overloaded routines)
   o after a routine has been parsed, it is now processed by
     cnodeutils.wrap_proc_body(), which can add extra nodes before code
     generation (used for injected the typed constant node trees)

git-svn-id: branches/jvmbackend@18475 -
2011-08-20 08:02:58 +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
bf21cd7a15 + support for (non-variant) arrayconstructornodes for the JVM target
o when allocating array temps for the JVM target, use the specified
     "forcesize" for the first dimension, since the arraydef size may
     be invalid (e.g., in case it's an array constructor)

git-svn-id: branches/jvmbackend@18468 -
2011-08-20 08:02:22 +00:00
Jonas Maebe
d13769204e * check for a tclassrefdef as the target conversion type in
asis_target_specific_typecheck, and if so get the real
    definition of its pointedtype rather than of the classrefdef
    itself (the latter would never be different from the original
    one, since there are no formal external classrefdef definitions)

git-svn-id: branches/jvmbackend@18467 -
2011-08-20 08:02:17 +00:00
Jonas Maebe
e663f0f31f + support for class constructors for the JVM target
o initialise class vars that need initialisations (records, arrays) in
     class constructors
   o treat class constructors as having a "void" resultdef rather than the
     class type for JVM (maybe has to be done in general?)
   o make it possible to specify pno_noleadingdollar to
     tprocdef.customprocname() so it can be used for class constructors
     (their name is lower cased because it mustn't conflict with other
      identifiers, since their name doesn't matter anyway)
   o added tsk_empty synthetic procdef kind which, as the name implies,
     generates an empty body (for class generated constructors)
  + auto-generate class constructors in case a class has class vars that
    need initialisation

git-svn-id: branches/jvmbackend@18462 -
2011-08-20 08:01:51 +00:00
Jonas Maebe
c264c24fb0 + support for unit initialisation sections for the JVM target,
and initialise global variables that are wrapped (records, arrays)
    in those sections
   o check whether pd.localst is assigned in dbgjasm, because it's
     not for the unit initialisation routine
   o moved insertbssdata() from ncgutil to ngenutil and override it
     njvmutil (it does nothing in the latter, since global variables
     are added as fields to the class representing the unit; the
     initialisation is done in gen_initialize_code() in thlcgjvm)
   o added force_init() and force_final() methods to ngenutil, so
     that targets can force init/final routines separate from the
     regular managed types infrastructure (used by JVM for forcing
     an init section in case of records/arrays)

git-svn-id: branches/jvmbackend@18460 -
2011-08-20 08:01:39 +00:00
Jonas Maebe
d79160a6af * correctly handle explicit typecasts between records and jlobject/
fpcbaserecordtype for the JVM target (intercept in ncnv via new
    target_specific_general_typeconv helper, handle in as/is code)
  * not only check for related types in htypechk in case they are
    objdefs, but always do so (records are related to jlobject/fpcbaserecord
    on the JVM target)

git-svn-id: branches/jvmbackend@18458 -
2011-08-20 08:01:29 +00:00
Jonas Maebe
cc6a303ee2 * allocate/initialize implicit pointer type fields (arrays, records) in
JVM classes after calling the inherited constructor (before doing
    so, self is not yet valid)

git-svn-id: branches/jvmbackend@18456 -
2011-08-20 08:01:24 +00:00
Jonas Maebe
a5af71a8d8 * don't remove regalloc/regdealloc pair if it's immediately followed by a
use of the register (can happen if the register is unused afterwards;
    remove the alloc/dealloc results in no temp being allocated for the
    register, so that instruction becomes invalid)

git-svn-id: branches/jvmbackend@18455 -
2011-08-20 08:01:19 +00:00
Jonas Maebe
da064b0ad6 * changed trgcpu.do_spill_replace_all() from a function (that doesn't set
its function result) into a procedure

git-svn-id: branches/jvmbackend@18454 -
2011-08-20 08:01:15 +00:00
Jonas Maebe
89e70f347c * do nothing for initialising temps in advance for the JVM target as that
happens automatically when required (for constructing arrays/records;
    reference counted types don't need special treatment since everything
    is garbage collected)

git-svn-id: branches/jvmbackend@18453 -
2011-08-20 08:01:10 +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
88df6573a0 * moved de2regtyp() from defutil to hlcgobj, so it can be overridden
(and override for the JVM, making the register type for records
     R_ADDRESSREGISTER instead of R_INTREGISTER there)

git-svn-id: branches/jvmbackend@18448 -
2011-08-20 08:00:31 +00:00
Jonas Maebe
c5b39823e5 + internalerror when passing handling invalid integer size in loadstoreopc()
git-svn-id: branches/jvmbackend@18443 -
2011-08-20 07:59:59 +00:00
Jonas Maebe
e58d783211 * dynamic arrays and open arrays need no conversion helper for JVM
git-svn-id: branches/jvmbackend@18424 -
2011-08-20 07:58:29 +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
254636ab84 * don't create (useless) temporary array/record/... for the result
of functions at the caller side, since these will already be allocated
    at the callee side
  * added comment to cpupara explaining why we never allocate the function
    result on the caller side and then pass it as an invisible parameter,
    but instead always let the callee allocate it

git-svn-id: branches/jvmbackend@18420 -
2011-08-20 07:58:09 +00:00
Jonas Maebe
4adb9a7ceb - removed (non-working) implicit try/finally support for the JVM, and
disabled it under all circumstances on platforms that use garbage
    collection for managed types since it's not required there

git-svn-id: branches/jvmbackend@18418 -
2011-08-20 07:58:00 +00:00
Jonas Maebe
761ff19c7f * initialise local dynamic array variables to empty arrays rather than
to "nil", so that returning them to Java code does not return a nil
    pointer

git-svn-id: branches/jvmbackend@18417 -
2011-08-20 07:57:55 +00:00
Jonas Maebe
f58de91f0c + support for JVM string constants
git-svn-id: branches/jvmbackend@18416 -
2011-08-20 07:57:50 +00:00
Jonas Maebe
bf0b8503c9 * don't internalerror in decstack() if the evaluation stack becomes corrupted
in case -sr is used (-sr code cannot be compiled, and is only used for
    debugging; with -alr, the stack slot information is printed in the
    assembler file)

git-svn-id: branches/jvmbackend@18410 -
2011-08-20 07:57:22 +00:00
Jonas Maebe
8f2aacfed5 + support for (formal/untyped) constants (ordinal, floating point,
nil-pointers typecasted to a class type, strings)
   o escape ", \, #10 and #13 in string constants as required by Java

git-svn-id: branches/jvmbackend@18391 -
2011-08-20 07:55:41 +00:00
Jonas Maebe
737f9f5e90 * moved tabstractvarsym.jvmmangledbasename to the jvmdef unit as a separate
function, so it can be easily also used for constsym without adding
    JVM-specific routines to symtype or duplicating the routine without
    inheritance
  + added tconstsym support to jvmdef.jvmmangledbasename()

git-svn-id: branches/jvmbackend@18390 -
2011-08-20 07:55:36 +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
be4a27657b + support for nested Java classes
o tobjectdef.jvm_full_typename() now gets an extra parameter to determine
     whether or not the package name should be prepended, so it can be easily
     used to generate the name of the .j file and of the class name inside it

git-svn-id: branches/jvmbackend@18384 -
2011-08-20 07:55:03 +00:00
Jonas Maebe
fde622e050 * generate a loadvmtaddrnode wrapper around Java objectdef typenode arguments
to tasnode (like for regular Object Pascal classes)
  * don't collect WPO information for Java classes in tloadvmtaddrnode.pass_1()
    (devirtualization can't work for Java, since classes can always be loaded
     at run time, except for final/sealed classes -- but that's not yet
     implemented)
  + JVM is-node support, unified JVM type checking codegen for is- and as-nodes

git-svn-id: branches/jvmbackend@18383 -
2011-08-20 07:54:57 +00:00
Jonas Maebe
608572c63a * removed unused local variables
* fixed some "uninitialised function result" warnings for dummy routines

git-svn-id: branches/jvmbackend@18381 -
2011-08-20 07:54:37 +00:00
Jonas Maebe
e5ce390565 + support for indexing (dynamic) arrays on the JVM
git-svn-id: branches/jvmbackend@18379 -
2011-08-20 07:54:24 +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
a2a6b2fd1d + "reference" temps that sort of implement pointer-style functionality for
platforms that don't support pointers (by make a copy of all registers
    part of a reference)

git-svn-id: branches/jvmbackend@18377 -
2011-08-20 07:54:10 +00:00
Jonas Maebe
0e87627218 + gethltemp() to allocate a temp specifying full type information even
for regular temps. This is required for targets that need special
    handling of the temps depending on the type
  * converted most gettemp() calls to gethltemp() calls

git-svn-id: branches/jvmbackend@18376 -
2011-08-20 07:54:04 +00:00