Commit Graph
89 Commits
Author SHA1 Message Date
Alfred Wärnsäter c238ebeef4 major changes, very much WIP, experimenting with async 2021-06-22 14:04:31 +02:00
Martin Carlberg 8416390631 Fixed: Removed unused variables and statements in compiler 2020-12-22 20:16:30 +01:00
Martin CarlbergandGitHub 38dd776049 Fixed: JavaScriptCore (WebKit) has a limit at 65536 on number of arguments in a function. (#2891)
The compiler will crash for really large Objective-J files as the array with code segments will hit this limit.
The solution is to append the array segment by segment.
2020-06-30 20:53:28 +02:00
Martin CarlbergandGitHub 1c866931f3 New: The compiler will now create warnings for variables that are never read (#2871)
This new warning adds a lot of warnings in the Cappuccino frameworks. I have turned off
the warning in the Jakefiles when compiling most of the Cappuccino frameworks. But it is
on as default for any user projects.

So there is also a new feature to turn off/on warnings as a compiler flag.

These flags are (all flags are on as default):
-Wunused-but-set-variable                    Warning when a local variable is never read.
-Wshadow-ivar                                Warning when a local variable is shadowing an instance variable for the class.
-Wcreate-global-inside-function-or-method    Warning when creating a global variable inside a function or method.
-Wunknown-class-or-global                    Warning when a class or global variable is not known.
-Wunknown-ivar-type                          Warning when the type for an instance variable is not known.

To turn off a flag add a 'no-' prefix. Example: -Wno-unused-but-set-variable

For an example how to use it in a Jakefile please look at the Jakefiles in this commit.
2020-02-21 14:29:48 +01:00
Martin Carlberg 81c02f24c6 New: msgSend will return undefined instead of nil when the receiver is undefined.
The msgSend function has always returned nil if the receiver has been nil or undefined.
Example:

var a = undefined;
var b = [a someSelector]; // b = nil

The variable b is now nil.

This pull request adds the ability for the msgSend function to return undefined if the receiver is undefined. If the receiver is nil it still return nil.
The above example again:

var a = undefined;
var b = [a someSelector]; // b = undefined

The variable b is now undefined.

Background.
The use of nil in Objective-C corresponds to the use of null in C and C++ and stands for "no value". A fundamental function in Objective-C is when you send a message to a receiver that is nil the result is again a nil value. This can be very convenient as you don't need the check if a receiver is nil before sending a message to it.

Objective-J adds the ability the use class structures and message send functionality for Javascript in the same way as Objective-C adds this to C and C++. Javascript also has the value null and is handled in the same way for Objective-J. Javascript also has the value undefined that stands for "not yet defined". This can sometimes be confusing and many try to handle null and undefined as the same thing. This is almost what Objective-J and the Cappuccino frameworks always has been doing. They try to always check for both null and ``undefined and always return nil but never undefined. We can say that Objective-J understands undefined but will try to translate it to nil.

Why do we need this change.
Javascript has both null and undefined and Objective-J is a superset of Javascript. It is now very hard to use undefined in Objective-J code as it will always try to translate it to nil. There are some Javascript libraries that use both null and undefined values and they are very hard to use from Objective-J programs today.  Same if you decide to use nil and undefined as a value in your own Objective-J code. This small change will make undefined a full member of the Objective-J language. It should be as it is a superset of Javascript. The Cappuccino frameworks will still handle undefined but only return nil.

How will it impact.
Today most methods will never return undefined so this is a very limited problem. If any does this the main concern is if some code will only check for nil and not undefined.
Example:

var a = [someObject someSelector];
If (a === nil) a = 42;
...

If the variable someObject contains undefined the variable a will now be set to undefined instead of nil.  But the variable a will then never be set to 42.
The correct way is to check for both nil and undefined like this:

var a = [someObject someSelector];
If (a == nil) a = 42;
...
2019-06-24 17:36:15 +02:00
Martin Carlberg 76f2d15b1b Fixed: Added the option to only inline message send function without also compress the output javascript file.
This allows us to inline the message send function in DEBUG mode. This is great when stepping into a method in the debugger as the message send function is not a separate function. Also the stack traces in the debugger is much more compact as the message send function is not there.
2017-12-08 14:02:11 +01:00
Martin Carlberg 8cf79590c5 Fixed: When target was ’self’ in a message send expression the source map was showing the wrong variable. 2017-09-12 13:17:49 +02:00
Martin Carlberg 94a5995197 New: We now support source maps when compiling both from command line and in browsers.
To add source maps add the ”-S” flag to the Jake file when compiling from command line. In the browser you need to add the compiler option into your index.html file. It should look something like this:
OBJJ_COMPILER_FLAGS = [... , "SourceMap"];

All browsers has support for source maps but currently Chrome works best.
2017-09-11 12:49:59 +02:00
Martin Carlberg 033e8583db Fixed: A more robust prettify message function 2017-06-26 17:59:08 +02:00
Martin Carlberg 195b109a36 New: Added ’#include’ to the preprocessor, compiler and Cappuccino load system. Also a lot of bug fixes in the preprocessor 2017-06-26 16:19:56 +02:00
Martin Carlberg a8ec5cf5e9 New: Support to create source maps for the frameworks and applications 2017-06-26 16:03:20 +02:00
Martin Carlberg 024c0a3186 Fixed: Handle source maps if source-map.js is included from the index.html file.
To create source maps the compiler flag ”SourceMap” has to be added in the OBJJ_COMPILER_FLAGS array in the index.html file.
2017-06-22 11:05:16 +02:00
Martin Carlberg d0cd976246 Fixed: Get class method instead of instance method
When asking a protocol for a specific class method we asked each super protocol for an instance method.

Thanks Frank for finding this!
2017-04-11 12:30:16 +02:00
Martin Carlberg 530db4e904 Fixed: Merged in the same parser and compiler that is used in the objj-runtime that is running on node.
The life will be easier to have the same in both environments.
Warnings and errors now don’t use read only properties for line and column information. So the test cases in Toolstest.j now work in modern JS engines.
It is also easier to set options for the compiler.
2016-04-07 10:32:46 +02:00
Martin Carlberg b132a66707 Fixed: Compiler option 'IncludeTypeSignatures' is default turn on for all type of builds. It can optionally be turned off. 2015-11-20 12:33:00 +01:00
Martin Carlberg 101261ca63 Fixed: Optionally inline objj_msgSend function. Generate faster code for Array and Dictionary Literals. 2015-10-06 13:30:09 +02:00
Alexandre Wilhelm d358f0d27b Fixed: xml format now has the key sourcePath instead of path for the command objj and objj2objcskeleton 2015-06-08 10:30:54 -07:00
Alexandre Wilhelm 0e41365020 Fixed: some objj errors were not print in xml when necessary 2015-06-01 13:53:41 -07:00
Alexandre Wilhelm 3102c545ce Fixed: used url path (/Users/..) instead of absoluth path (file://Users/..) in the xml output format of objj 2015-05-25 13:26:37 -07:00
Alexandre Wilhelm 204ed1f257 New: added the option --xml-output-format for the command objj
Previously, it was not possible to specify the desired output format of the command objj.
Now we can have either the default format or a xml format if --xml-output-format is added.
2015-05-25 11:20:55 -07:00
Martin Carlberg a924fd0e7e Fixed: Generate compiler error when ivar is already declared in superclass 2015-03-03 11:32:18 +01:00
Martin Carlberg ee13978115 Fixed: @ref did not generate self.x for an ivar x 2014-12-02 13:54:02 +01:00
Antoine Mercadal 31afae71d1 Typos 2014-11-26 11:52:25 -08:00
Antoine Mercadal 37b9895878 Add check to ensure a @class declaration is not already defined as a type 2014-11-20 11:44:32 -08:00
Antoine Mercadal 9e66c699e1 FIXED: prevent to declare a type that is already declared as a class and vice-versa 2014-11-19 14:35:33 -08:00
Antoine Mercadal 8ee443a43c NEW: @typedef and ivar type warning
Previously, ObjJ was ignoring unknow ivar type. This patch adds some check to ensure the type is either a known class, the current class
itself, a global, a basic JS type or a declared custom type.

In order to declare custom types, this patch introduces the @typedef keyword.

For instance, this will throw a warning:

```objj
@import <Foundation/Foundation.j>

@implementation MyClass: CPObject
{
    NUSuppaType mode;
}
@end
```

This will not:

```objj
@import <Foundation/Foundation.j>

@typedef NUSuppaType

@implementation NUMyClass: CPObject
{
     NUSuppaType mode;
}
@end
```

Declared types are shared accross all application, one type can only be declared once.
2014-11-06 10:10:05 -08:00
Antoine Mercadal 73a2823d0b Merge pull request #2213 from mrcarlberg/error_cannot_find_protocol_declaration
Fixed: When the compiler can't find a protocol in a class declaration
2014-09-30 16:56:36 -07:00
Martin Carlberg 2f7681f881 Fixed: No line information was provided for compiler errors on the first line of a file 2014-09-26 13:28:44 +02:00
Martin Carlberg 13fe318110 Fixed: When the compiler can't find a protocol in a class declaration it now gives an understandable error.
This fixes #2212
2014-09-16 20:13:42 +02:00
Antoine Mercadal 371b660b33 Merge pull request #2072 from mrcarlberg/fix_accessors_in_categories_fails
Fixed: Ivars with accessors in a Category failed with duplicate ivar error
2014-09-04 14:02:53 -07:00
Martin Carlberg e8e10d4224 Fixed: If receiver in the function objj_msgSend is a class we don't need to check if it is nil as a class can never be nil without the load has already failed. 2014-04-15 13:52:41 +02:00
Martin Carlberg 81e4b6b37b Fixed: If the function 'eval' is called it might have altered 'self' and from here on we check if 'self' is null before 'objj_msgSend' is called with 'self' as receiver 2014-04-14 16:37:21 +02:00
Martin Carlberg b1507952df Fixed: Checks if 'self' is nil only if self has a chance to be changed when sending messages 2014-04-11 15:41:32 +02:00
Martin Carlberg c23292db8a Fixed: Optimized msgSend code when receiver is an identifier.
If the receiver is an identifier and not an ivar that needs 'self.' infront there is no need to assign it to a temporary variable. Also if the identifier is 'self' there we assume it is not nil.
2014-04-10 18:27:19 +02:00
Martin Carlberg 2411edd461 Fixed: Faster objj_msgSend
Conflicts:
	Objective-J/Runtime.js
2014-04-08 20:51:18 +02:00
Martin Carlberg ee668df440 Fixed: Ivars with accessors in a Category failed with duplicate ivar error 2014-02-21 12:27:52 +01:00
Alexander Ljungberg c1f538ece5 Formatting: whitespace.
Refs #1974.
2013-11-28 18:39:01 +00:00
Martin Carlberg 8419001810 Merge branch 'master' of https://github.com/cappuccino/cappuccino into protocol 2013-11-22 14:23:52 +01:00
Martin Carlberg f0e2daf6c7 Fixed: Add get and set instance methods to class definition when ivar has accessors.
This caused 'Method is not implemented' warnings when a class implemented protocol declared set and get methods as 'accessors' on an ivar.
2013-09-12 21:54:57 +02:00
Martin Carlberg 9f0d8c54e4 Fixed: Uses current protocolDefs when compiling accessors
This caused 'null is not an object' type error when class declaration with 'accessors' declared ivars was in the same file as the protocol it was conforming to.
2013-09-12 21:47:15 +02:00
Martin Carlberg 23fb618596 Fixed: Compiler now generates correct empty statement after 'if (a);'
Earlier the compiler generated the 'if' without the last ';' when a empty statement is used, with sometimes devastating result. The same if an empty statement was after the 'else'.

I have also added a test case for some different empty statement senarios.
2013-09-09 16:38:38 +02:00
Martin Carlberg ba0604320e Fixed: Should be 'objj_allocateProtocol' and 'objj_registerProtocol' not 'objc_allocateProtocol' and 'objc_registerProtocol' 2013-08-31 15:33:32 +02:00
Martin Carlberg c979a69e6b Fixed: Compiler can now handle only @action/IBAction declared return type when checking for 'Conflicting return type' method declaration.
Also made the warning message point to correct return type token when type is not declared.
2013-08-28 11:23:55 +02:00
Martin Carlberg 9eebb0a64b Fixed: Pass correct node to error message when finding duplicated protocol 2013-08-22 16:53:22 +02:00
Martin Carlberg cfc682c165 Fixed: Protocol methods is now registered in the correct place 2013-08-22 12:36:29 +02:00
Martin Carlberg c326168e83 Fixed: Protocol definition in compiler was not created correct from protocol definition in the runtime 2013-08-22 12:35:16 +02:00
Martin Carlberg b8b96a17d7 Fixed: Check if global function exists in correct way 2013-08-22 12:34:14 +02:00
Martin Carlberg 672ed6ed0c Fixed: Handle protocol declaration with no method declarations 2013-08-12 22:41:36 +02:00
Martin Carlberg f74312dc42 Fixed: Allow type on return or parameter type to be a class if superclass or protocol declared it as 'id' 2013-08-12 16:55:35 +02:00
Martin Carlberg 2e216d7e9a Fixed: Make default return type to 'void' for '@action' or 'IBAction' marked method. 2013-08-12 16:53:19 +02:00