Adding symbol resolving, type checking, inheritance and polymorphism

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding symbol resolving, type checking, inheritance and polymorphism

jacklack
This post was updated on .
After finishing the Jack compiler, I added to it symbol resolving, type checking, inheritance and polymorphism.

These makes it more robust, less error prone (type checking and symbol resolving) and more powerful (inheritance and polymorphism).

I would like to know if there are people who would like to work on this further, my aim is to be able to generate x86 windows executable using the Jack compiler/vmtranslator/assembler source.

And of course add to it any improvement in the language or any of the builders (compiler/vm/assembler).

I have the project on Github, if anyone is interested and would like to contribute to it (and help and learn in the process) please reply to this thread or contact me here _designerjgames@yahoo.com_ (remove the underscore _ in the email (I added it to avoid spam)).

Thank you;
Reply | Threaded
Open this post in threaded view
|

Re: Adding symbol resolving, type checking, inheritance and polymorphism

jacklack
I started on adding support of member objects access (fields and statics).
This is to allow direct object fields manipulation, like:

objectA.FieldB = objectC

This looks to be a challenging task, as in addition to not knowing the object types when parsing them, allowing such object access means also handling expressions like:

objectA.methodA()[10].FieldB[12].FieldC.MethodB().... etc...

Thats is fields as arrays, fields of functions return type, field of field, etc...
For example, methodA is returning an array, and we take the 10'th object in it and access the 12 object in it's field array B which then access fieldC which calls MethodB() etc...
Reply | Threaded
Open this post in threaded view
|

Re: Adding symbol resolving, type checking, inheritance and polymorphism

ivant
Sounds like an interesting project. Some time ago I was thinking about replacing the VM from the course with LLVM and you may want to check it out. I'm sure, that one would be able to compile (extended) Jack to LLVM and this would allow you to generate native code for many different platforms.

I'm not so sure if HACK is a feasible target machine, as it's quite restricted and I only know the big picture in LLVM.
Reply | Threaded
Open this post in threaded view
|

Re: Adding symbol resolving, type checking, inheritance and polymorphism

jacklack
Hi ivant, thanks for the suggestion about LLVM.

It certainly is a great option to have Jack compiled on multiple platforms without drowning into the assembly level and platform specific executable architecture, which is a huge task (I had a look at the PE windows executable format, and the thing is rather complex).

Another nice option (for later) is to have LLVM generate Hack code...
Reply | Threaded
Open this post in threaded view
|

Re: Adding symbol resolving, type checking, inheritance and polymorphism

jacklack
In reply to this post by jacklack
I completed the member field access, still it needs testing.

I added a lot of new functionality to Jack, while doing so, most of the changes were made to the compiler
a few to the virtual machine, and one to the assembler.
The list of additions and the areas it affected are listed here, along with my perceived difficulty of doing so:

- Added GE/LE (>=/<=) (greater or equal, less or equal) to the build stack. It affected all the modules : Compiler/VM/Assembler. Difficulty: easy.

- Added a new class to the compiler, I named it (resolver) as it resolves symbols and also do some extra work that I'll detail here.
Resolver resolves data types, for objects, fields, functions returns, function arguments, expressions, array indices etc... It checks that the symbol exists and check that the types conform. (for example, an array index must be of type int or int constant).
It also check expressions final type depending on the arithmethic used in them. For example an if statement must be handling a bool value.
And also it writes VM code that the compiler couldn't figure out.
Affects: Compiler, Difficulty: Hard.

- Added casting, so that we can cast types for example from a derived to base class.Affects: Compiler, Difficulty: medium.

- Added inheritance. Affects: Compiler, Difficulty: medium.

- Added calls to parent functions. Affects: Compiler, Difficulty: medium.

- Added polymorphism (Virtual functions). Affects: Compiler/VM, Difficulty: hard.

- Added multidimentional arrays (no limit on the dimensions) Affects: Compiler, Difficulty: medium.

- Made arrays to contain objects of a user defined type (array of ints, of char, of object type etc...) Affects: Compiler, Difficulty: medium.

- Objects fields access (with field being object or function or buit in types), access of composition hierarchy of any length. Affects: Compiler, Difficulty: hard

- Added operator to take object address, or function address  Affects: Compiler/vm, Difficulty: medium

- Added an error module to report compiler and resolver errors. Affects: Compiler, Difficulty: easy.

Next I will do function overrloading (overriding is already done (polymorphism) ).
Reply | Threaded
Open this post in threaded view
|

Re: Adding symbol resolving, type checking, inheritance and polymorphism

jacklack
I have uploaded the files related to this compiler to: https://github.com/designerjgames/Jack