Dynamic Method Invocation Compilation in Statically-Typed Languages
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Statically-typed programming languages face challenges in compiling and executing dynamically-typed method calls, particularly when such calls contain illegal characters or require type definitions not available at compile-time, leading to inefficiencies and errors.
Innovation Solution
A method and system that differentiate between static and dynamic method calls in a statically-typed programming environment, allowing dynamic method invocations to be compiled without type checking and enabling the use of reserved types for dynamically-typed methods, thus avoiding compile-time method selection and illegal character errors.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Adaptability or versatility
If type checking is performed at compile-time for all method calls in a statically-typed programming language, then type safety is ensured, but dynamically-typed method calls containing illegal characters or requiring type definitions not available at compile-time cannot be compiled
Solution Approach 1:
The patent segments method calls into two distinct categories: static method calls and dynamic method calls. Static method calls undergo traditional compile-time type checking, while dynamic method calls are handled differently. This segmentation allows the system to maintain type safety for static calls while enabling flexibility for dynamic calls through runtime resolution, resolving the contradiction between adaptability and reliability.
Solution Approach 2:
The patent introduces an intermediary mechanism (dynamic method invocation interface) that bridges statically-typed and dynamically-typed method calls. This intermediary allows dynamic method calls with illegal characters or undefined types to be compiled without triggering type checking errors, while still maintaining type safety through runtime validation. The intermediary acts as a mediator that reconciles the conflicting requirements of compile-time type safety and runtime flexibility.
2Adaptability or versatility
If traditional reflective API calls are used to handle dynamic method invocations, then dynamically-typed methods can be invoked, but processing efficiency decreases and resource usage increases
Solution Approach 1:
The patent performs preliminary actions during the compilation phase by creating optimized method invocation structures for dynamic method calls. Instead of using heavy reflective API calls at runtime, the compiler prepares optimized bytecode that directly invokes dynamic methods with reduced overhead. This preliminary preparation eliminates the need for inefficient runtime reflection, thereby improving processing efficiency while maintaining dynamic method invocation capability.
3Manufacturing precision
If compile-time method selection is performed for all method calls, then type definitions must be available at compile-time, but this causes errors when type definitions are not available
Solution Approach 1:
The patent introduces dynamic method invocation as a distinct mechanism that operates differently from static method calls. For dynamic method calls, the system does not require type definitions to be available at compile-time. Instead, method selection and validation are performed dynamically at runtime based on actual type information. This dynamic approach allows the system to handle methods without compile-time type definitions while maintaining method selection accuracy through runtime type checking.
Data Source
AI summary
A method for compiling source code, involving: obtaining a statement of the source code comprising a method call, where the source code is composed in a statically-typed programming language; determining whether the method call is a dynamic method call; upon determining that the method call is a dynamic method call, compiling a dynamic method invocation without performing type checking on the method call; upon determining that the method call is not a dynamic method call: performing type checking on the method call, selecting a target method to invoke, and compiling a static method invocation to invoke the target method.


