Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #1131 > unrolled thread
| Started by | Anthony Williams <awgold70@gmail.com> |
|---|---|
| First post | 2014-03-05 06:27 -0800 |
| Last post | 2014-03-10 10:23 -0700 |
| Articles | 6 — 5 participants |
Back to article view | Back to comp.compilers
Language translation Anthony Williams <awgold70@gmail.com> - 2014-03-05 06:27 -0800
Re: Language translation Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2014-03-05 16:42 +0100
Re: Language translation Kaz Kylheku <kaz@kylheku.com> - 2014-03-05 16:08 +0000
Re: Language translation Jens Kallup <jkallup@web.de> - 2014-03-06 20:31 +0100
Re: Language translation Nor Jaidi Tuah <norjaidi.tuah@ubd.edu.bn> - 2014-03-10 08:37 +0800
Re: Language translation Anthony Williams <awgold70@gmail.com> - 2014-03-10 10:23 -0700
| From | Anthony Williams <awgold70@gmail.com> |
|---|---|
| Date | 2014-03-05 06:27 -0800 |
| Subject | Language translation |
| Message-ID | <14-03-009@comp.compilers> |
Dear Group, I'm facing the problem to translate language A into language B. The problem is, that A is an object oriented language (it supports classes, attributes of classes ...). But B is much simpler. It hasn't support for classes. There is only variables, functions. And my Question: How Could I Implement Classes in B. (At first it would be sufficient, if i could "emulate" simple classes, that don't support inheritance, function hiding, polymorphy ...) Thank you for your answer, A.W. [This is basicallly what compilers for OOP languages do -- they translate the OOP stuff into equivalent code for a much lower level language, typically assembler or machine language. There are fairly standard ways to do low level implemenations of OOP, with a tree of structures for each class with pointers to all of the class structures, and each class instance having a structure with a field for each data member and a pointer back to its class structure, with more or less extra stuff depending on how complex the inheritance system is. So you have to do that in language B. If this sounds really tedious, yes, it is. -John]
[toc] | [next] | [standalone]
| From | Hans-Peter Diettrich <DrDiettrich1@aol.com> |
|---|---|
| Date | 2014-03-05 16:42 +0100 |
| Message-ID | <14-03-010@comp.compilers> |
| In reply to | #1131 |
Anthony Williams schrieb: > Dear Group, > > I'm facing the problem to translate language A into language B. The > problem is, that A is an object oriented language (it supports > classes, attributes of classes ...). But B is much simpler. It hasn't > support for classes. There is only variables, functions. And my > Question: How Could I Implement Classes in B. (At first it would be > sufficient, if i could "emulate" simple classes, that don't support > inheritance, function hiding, polymorphy ...) Just rephrasing what John said, in my own words and view: An emulation typically adds an this/self instance reference to the parameter list of every method. "Real" OO languages simply hide this parameter in the source code, i.e. the compiler changes the parameter list and calls accordingly. That's what your translator should add to the translated source code. That's all about basic (static) methods. Instance data is a record (struct...), containing all data fields of the class. BTW the first C++ compiler was such a translator, from C++ to C. I don't remember its name, but it should be available in the museum - John? DoDi [cfront which you can find at http://www.softwarepreservation.org/projects/c_plus_plus -John]
[toc] | [prev] | [next] | [standalone]
| From | Kaz Kylheku <kaz@kylheku.com> |
|---|---|
| Date | 2014-03-05 16:08 +0000 |
| Message-ID | <14-03-011@comp.compilers> |
| In reply to | #1131 |
On 2014-03-05, Anthony Williams <awgold70@gmail.com> wrote: > Dear Group, > > I'm facing the problem to translate language A into language B. The > problem is, that A is an object oriented language (it supports > classes, attributes of classes ...). But B is much simpler. It hasn't > support for classes. There is only variables, functions. And my > Question: How Could I Implement Classes in B. ... It may not be possible if language B doesn't have things like pointers, aggregate types such as vectors, or function indirection. This question is too vague in its current form, lacking a detailed specification of A and B. [Of course it's possible unless the language is weaker than Tiny Basic. But it might be really ugly, e.g., parallel arrays to simulate structures and glue functions that dispatch on an index parameter to sort of fake function pointers. Like I said, it's tedious. -John]
[toc] | [prev] | [next] | [standalone]
| From | Jens Kallup <jkallup@web.de> |
|---|---|
| Date | 2014-03-06 20:31 +0100 |
| Message-ID | <14-03-012@comp.compilers> |
| In reply to | #1131 |
Hello,
for my compiler, i do some test's.
when i had a class "Aclass", then i check it's parent.
It can be "Acustom", or an other class "Aform".
So, i have 2 types:
Acustom // parent (super)
Aclass // my plain class
Acustom // parent (super)
Aform // form class (window)
Aclass // class -> Aform = parent
You can build a tree:
CLASS Aform // you can leave the parent, if you know it is Acustom
...
ENDCLASS
CLASS Aclass OF Aform
...
ENDCLASS
Then you can build code:
(All classes becomes numbers - you reserve a part
for your static parents...)
push 10 ; push 10 (Aform - if you wish it is a window)
push 0 ; parent (window) class
push CNAME ; rtti - name the class
call create_class ; call function to create the class
; e.g. init window size
The best way is, you should consult the assembler code,
which is created by follpwing command:
gcc -S test.cc
cheers
Jens
[toc] | [prev] | [next] | [standalone]
| From | Nor Jaidi Tuah <norjaidi.tuah@ubd.edu.bn> |
|---|---|
| Date | 2014-03-10 08:37 +0800 |
| Message-ID | <14-03-017@comp.compilers> |
| In reply to | #1131 |
May I suggest you look at Vala (https://wiki.gnome.org/Projects/Vala) an OO language that compiles to C. The C code it produces is fairly human readable except for the heavy use of temp variables. Though Vala is intended to be used with GObject (a library to support object-orientation in C), it can be used without it. Nice day Nor Jaidi Tuah
[toc] | [prev] | [next] | [standalone]
| From | Anthony Williams <awgold70@gmail.com> |
|---|---|
| Date | 2014-03-10 10:23 -0700 |
| Message-ID | <14-03-018@comp.compilers> |
| In reply to | #1139 |
Thanx to all for your answers. This brings me closer to the thing :-) Best regards, A.W. Nor Jaidi Tuah wrote: > May I suggest you look at Vala (https://wiki.gnome.org/Projects/Vala) > an OO language that compiles to C. The C code it produces is fairly > human readable except for the heavy use of temp variables. Though Vala > is intended to be used with GObject (a library to support > object-orientation in C), it can be used without it.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.compilers
csiph-web