Quantcast

Object Orientation

classic Classic list List threaded Threaded
7 messages Options
Amanda Osvaldo Amanda Osvaldo
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Object Orientation

Hi everybody, i'm implementing object orientation in SciLAB, begin for inheritance, encapsulation, and aggregation.

With a syntax like:

class GeometricHandle

public attribute = 5;

public function calc(x)
return x = x * attribute;
endfunction

endclass

instance = GeometricHandle();
instance.calc(10);

-->

I'm searching for inspiration in Struct DataType. I believe I can use it as a base.

So, I need to ask.

What prevents me to insert a function inside a struct ?

Like someting: 

instance = struct();

instance.attribute = 5;
instance.calc = function(x) return x = x * attribute; endfunction;

Because of what i understood, in the Scilab's  core the  struct datatype uses a class named SingleStruct , which in turn,  uses the class InternalType to handle the struct's content.

And the class InternalType can handle functions.

If someone has a better idea I would like to listen.

-- Amanda Osvaldo

_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Clément David-2 Clément David-2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Object Orientation

Hi Amanda,

> I'm searching for inspiration in Struct DataType. I believe I can use it as a base.
>
> So, I need to ask.
>
> What prevents me to insert a function inside a struct ?

Nothing :) ! From the user point of view, a function can be passed by value and called later.

> Because of what i understood, in the Scilab's  core the  struct datatype uses a class named
> SingleStruct , which in turn,  uses the class InternalType to handle the struct's content.
>
> And the class InternalType can handle functions.
>
> If someone has a better idea I would like to listen.

Some times ago, a detailed analysis has been done to implement (aka emulate as this is not native)
an object oriented paradigm. Like in Javascript or Python, the user should just follow some coding
conventions to define the object and pass it around. However I prefer using an mlist() rather than a
struct() to avoid multi-dimensional issues ; a struct() have multiple dimensions defined by :

a.b = 1;
a // 1x1 struct
a(4,5).b = 2; // resize a
a // 4x5 struct with empty "b" values

Do not hesitate to contribute and edit the wiki if you need / look for more tests !

[1]: https://wiki.scilab.org/Emulate%20Object%20Oriented%20in%20Scilab

Thanks,

--
Clément
_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Amanda Osvaldo Amanda Osvaldo
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Object Orientation

Hi Clément.

I'm happy to know the community appreciate the object oriented approaching in SciLAB.

I want to start with a fake Object Orientation, however, how I can learn about the SciLAB's bytecodes to implement a true Object Orientation ?

-- Amanda Osvaldo

On Mon, 2017-02-20 at 10:36 +0100, Clément David wrote:
Hi Amanda,

I'm searching for inspiration in Struct DataType. I believe I can use it as a base. So, I need to ask. What prevents me to insert a function inside a struct ?
Nothing :) ! From the user point of view, a function can be passed by value and called later.
Because of what i understood, in the Scilab's  core the  struct datatype uses a class named SingleStruct , which in turn,  uses the class InternalType to handle the struct's content. And the class InternalType can handle functions. If someone has a better idea I would like to listen.
Some times ago, a detailed analysis has been done to implement (aka emulate as this is not native) an object oriented paradigm. Like in Javascript or Python, the user should just follow some coding conventions to define the object and pass it around. However I prefer using an mlist() rather than a struct() to avoid multi-dimensional issues ; a struct() have multiple dimensions defined by : a.b = 1; a // 1x1 struct a(4,5).b = 2; // resize a a // 4x5 struct with empty "b" values Do not hesitate to contribute and edit the wiki if you need / look for more tests ! [1]: https://wiki.scilab.org/Emulate%20Object%20Oriented%20in%20Scilab Thanks, -- Clément _______________________________________________ dev mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/dev

_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Object Orientation

Hi Amanda,

Le 21/02/2017 à 19:48, Amanda Osvaldo a écrit :
Hi Clément.

I'm happy to know the community appreciate the object oriented approaching in SciLAB.

I want to start with a fake Object Orientation, however, how I can learn about the SciLAB's bytecodes to implement a true Object Orientation ?

You might find the top of the iceberg by editing the macro
--> edit tree2code
and by analysing the macr2tree() builtin function

HTH
Samuel


_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Amanda Osvaldo Amanda Osvaldo
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Object Orientation

Hi, it's very interesting.

I have followed it at sci_macr2tree.c that appears the macr2tree macro.

But i don't understand how sci_macr2tree.c separates the function code from all SciLAB's memory.
I think the SciLAB macro memory it's like a binary stream without any markers that define where a macro starts or ends.

Someone, tell me if I'm wrong.

Apropos, what it's te AST module ?
It appears a Virtual Machine with a parser.

-- Amanda

On Tue, 2017-02-21 at 21:49 +0100, Samuel Gougeon wrote:
Hi Amanda,

Le 21/02/2017 à 19:48, Amanda Osvaldo a écrit :
Hi Clément.

I'm happy to know the community appreciate the object oriented approaching in SciLAB.

I want to start with a fake Object Orientation, however, how I can learn about the SciLAB's bytecodes to implement a true Object Orientation ?

You might find the top of the iceberg by editing the macro
--> edit tree2code
and by analysing the macr2tree() builtin function

HTH
Samuel

_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev

_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Object Orientation

Le 21/02/2017 à 22:19, Amanda Osvaldo a écrit :
Hi, it's very interesting.

I have followed it at sci_macr2tree.c that appears the macr2tree macro.

But i don't understand how sci_macr2tree.c separates the function code from all SciLAB's memory.
I think the SciLAB macro memory it's like a binary stream without any markers that define where a macro starts or ends.

Someone, tell me if I'm wrong.

Apropos, what it's te AST module ?

It is the Abstract Syntax Tree of Scilab to interpret Scilab language
I guess that all rules to parse Scilab codes are now defined there.
https://en.wikipedia.org/wiki/Abstract_syntax_tree


_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Clément David-2 Clément David-2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Object Orientation

Hi Amanda and Samuel,

Le mardi 21 février 2017 à 22:34 +0100, Samuel Gougeon a écrit :
> > But i don't understand how sci_macr2tree.c separates the function code from all SciLAB's memory.
> > I think the SciLAB macro memory it's like a binary stream without any markers that define where
> > a macro starts or ends.

Just to clarify and provide more information about the global design of Scilab 6 by my
understanding.

There is only one module called "ast" [1] involved in parsing, interpreting, values (or types)
definition. Sub-directories (both inside includes/ or src/cpp/) implement theses behaviors.

A bison/flex parser is used to allocate Exp (for expressions) [2] based on the syntax, all the Exp
objects then represent an abstract syntax tree of any Scilab code.

To interpret the code, we do use intermediate bytecode but simply implemented a "visitor pattern"
that traverses the Exp objects interpreting each Exp and passing values around. So the old-school
switch/case bytecode interpreter is replaced by a `visit(Exp*)` function dispatch for each Exp
class.

Values allocated by matrix definitions (by the parser) or function calls are all defined by Type
objects [3]. And most of our gateways are now using these internal Type management rather than API
Scilab to distinguish internal API and external API (aka API Scilab).

Note: the macr2tree is implemented as a visitor that encode each Exp to a specific Type, it just
traverses the Exp tree to reproduce a Scilab 5 compatible values encoding.


[1]: modules/ast
[2]: modules/ast/includes/exps and modules/ast/includes/exps/exp.hxx
[3]: modules/ast/includes/types and modules/ast/includes/types/internal.hxx

Regards,

--
Clément
_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Loading...