Commit Graph

34 Commits

Author SHA1 Message Date
Jonas Maebe
9cbff6f5a6 + support for record constructors for the JVM target
git-svn-id: trunk@23510 -
2013-01-24 09:45:12 +00:00
Jonas Maebe
3abc7b0d9c * removed superfluous check (a procvardef can never be a constructor) and
typecasts

git-svn-id: trunk@23509 -
2013-01-24 09:45:06 +00:00
Jonas Maebe
1955255dda * let thlcg.a_call_name() return the tcgpara representing the function
result location (NR_FUNCTION_RESULT_REG is not valid on all platforms)
   o this requires passing the forced function result type (if any) to this
     method
   o a generic, basic thlcg.a_call_name() is now available that sets the
     function result location; can be called by descendants
  * the availability under all circumstances of the correct function return
    type enables g_call_system_proc() on the JVM platform to now determine
    by itself how many stack slots are removed by the call -> do so, instead
    of manually counting them (or forgetting to do so and messing up the
    maximum evaluation stack height calculations)

git-svn-id: trunk@21862 -
2012-07-11 08:25:58 +00:00
Jonas Maebe
94b058fe19 * fixed version of r20547: can't check the number of abstract methods of a
class before its VMT has been built, because that's the process that looks
    for inherited abstract methods that are overridden -> instead use a new
    synthetic method kind (tsk_callthrough_nonabstract) that will call
    through to another method (in this case a constructor) if the owning
    class does not contain any abstract methods, and generates an
    empty routine otherwise

git-svn-id: branches/jvmbackend@20589 -
2012-03-23 11:26:30 +00:00
Jonas Maebe
1401c4e573 * fixed popping the unused function results of methods returning implicit
function pointer type results (records, shorstrings, ...): always pop a
    single stack slot in that case

git-svn-id: branches/jvmbackend@19598 -
2011-11-06 14:01:12 +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
633de3fe30 * give an error when calling a virtual constructor from another constructor
on the JVM target, because the generated code was invalid and I can't think
    of a generic way to solve it (see added comments in njvmcal.pas)

git-svn-id: branches/jvmbackend@19055 -
2011-09-12 18:08:46 +00:00
Jonas Maebe
1a7c024ad3 * sign extend all byte/ansichar/word parameters before passing them
to and returning them from sub routines, in order to follow the JVM
    specs to the letter (not checked by the JVM bytecode verifiers, but
    checked by the Android DEX verifier)
  * -> also zero-extend them again at the caller side after returning
    from such a function

git-svn-id: branches/jvmbackend@18919 -
2011-08-30 23:34:12 +00:00
Jonas Maebe
6a7ff1cf75 * use temp-reference nodes rather than addrnodes to create references to
complex parameters passed to inlined routines on the JVM target, because
    it is not possible to take the address of any kind of node on the JVM
    target (temp-reference nodes work for any kind of LOC_(C)REFERENCE, but
    are currently only implemented for the JVM platform)

git-svn-id: branches/jvmbackend@18905 -
2011-08-29 22:58:55 +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
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
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
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
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
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
9de14768bb * free temp location allocated for function result if not used
* don't free function result space on stack twice if the result
    is not used but a the same time has already been stored in a
    temporary funcretnode location

git-svn-id: branches/jvmbackend@18556 -
2011-08-20 08:10:05 +00:00
Jonas Maebe
58d7a86252 + stubbed formal const/var/out support
git-svn-id: branches/jvmbackend@18552 -
2011-08-20 08:09:45 +00:00
Jonas Maebe
c9537e3347 + support for non-array/record var parameter on the JVM target using
copy-in/out

git-svn-id: branches/jvmbackend@18527 -
2011-08-20 08:07:24 +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
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
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
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
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
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
Jonas Maebe
df2d83f110 * fixed calculating the number of stack slots removed by a call
(pushedparasize is already expressed in number of stackslots rather
    than in bytes)
   o when determining the number of stack slots to pop after calling a function
     and not using its function result, round up the function result size to
     the nearest multiple of 4 before determining the number os tack slots (to
     correctly handle byte/word-sized results)

git-svn-id: branches/jvmbackend@18362 -
2011-08-20 07:51:42 +00:00
Jonas Maebe
e699eb3cc5 + added "list" parameter to thlcgjvm.inc/decstack() methods, and
in case of -ar add to the assembler output the height of the
    evaluation stack every time it's increased or decreased (to
    more easily track missing/wrong inc/decstack() operations)

git-svn-id: branches/jvmbackend@18335 -
2011-08-20 07:48:00 +00:00
Jonas Maebe
eb5814a868 * implemented declaring and calling constructors for Java classes
o handle them like for regular classes (return a class instance,
     although this is technically not true since they don't return
     anything; will be changed in the future)
   o because of the previous point, make sure that we handle the
     "function result" properly and don't pop too many values from
     the evaluation stack when calling one constructor from another
   o added "extra_pre_call_code" method used by njvmcal to insert
     the "new" opcode to create the new class instance before
     calling a constructor
   o when a constructor does not call any other constructor (inherited
     or otherwise), automatically insert a call to the inherited
     parameterless constructor as required by the jvm standard)
   TODO: check that *if* an inherited or other constructor is called
     from another constructor, that it does so as the first statement/
     call

git-svn-id: branches/jvmbackend@18328 -
2011-08-20 07:46:37 +00:00
Jonas Maebe
e2e32fbbe9 * fixed temp leaking after release_unused_return_value_cpu() refactor:
renamed refactored routine to do_release_unused_return_value()
    which by default releases temps, and if something else needs to
    be done override (and call inherited if temps may have to be
    released)

git-svn-id: branches/jvmbackend@18327 -
2011-08-20 07:46:31 +00:00
Jonas Maebe
9a9ea1f257 + limited thlcg.gen_load_cgpara_loc() implementation (only loc_reference
support), passed through to original ncgutils version in thlcg2ll
  + thlcgobj.location_force_mem() implementation
  * order parameters for jvm similar to those for i386 without fixed_stack,
    so we don't need temporary paralocations
  * converted most of ncgcal to thlcg
  * disabled special handling for virtual methods for jvm in ncgcal, as all
    invocations are name-based there
  + njvmcal with special jvm callnode support:
   o always move the function result into a memory temp
   o when freeing an unused function result, use a_pop(2) and adjust
     the internal evaluation stack height counter
   o after the call instruction, adjust the evaluation stack height counter
     by subtracting the number of the pushed parameter slots, adjusted for
     the slots taken up by the function result

git-svn-id: branches/jvmbackend@18325 -
2011-08-20 07:46:22 +00:00