Extending RedLine

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Extending RedLine

Benoit St-Jean-4
Is there a way to extend an existing class (say, Integer) without having to modify the core Integer.st file?  I want to add 2-3 methods to the Integer class but I'm wondering if there's a way to do so without modifying the "original" file?
Reply | Threaded
Open this post in threaded view
|

Re: Extending RedLine

James Ladd
Of course, this is Smalltalk.

You need to send messages to the Integer class.
I'll post an example in two hours - travelling right now.
- James

Sent from Hyperspace.

On 03/12/2012, at 9:09 AM, Benoit St-Jean <[hidden email]> wrote:

> Is there a way to extend an existing class (say, Integer) without having to modify the core Integer.st file?  I want to add 2-3 methods to the Integer class but I'm wondering if there's a way to do so without modifying the "original" file?
Reply | Threaded
Open this post in threaded view
|

Re: Extending RedLine

James Ladd
To extend an existing class in Redline Smalltalk requires you to send
a message to the class you want to extend to add a new method.

For example:

To add the instance method 'floor' to the Float class we send the
atSelector:put: message to the Float class -

Float atSelector: #floor put: [
   "code that does the floor math."
].

To add the class method 'random' to the Integer class we send the 
atSelector:put: message to the class of the Integer class -

Integer class atSelector: #random put: [
   "code that does the random generation."
].

The code inside the blocks is standard Smalltalk.

Arguments are catered for by adding arguments to the passed in block.
For example:

Integer class atSelector: #randomBetween:and: put: [ :low :hi |
   "code that does the random generation between low and hi."
].

Internally Redline sends these exact same messages when adding the methods
defined in a Class using the -/+.

For example, in class Object:

- yourself
  ^ self.

Becomes:

Object atSelector: #yourself put: [
    ^ self.
].

I hope this helps.

- James.

On Mon, Dec 3, 2012 at 9:36 AM, James Ladd <[hidden email]> wrote:
Of course, this is Smalltalk.

You need to send messages to the Integer class.
I'll post an example in two hours - travelling right now.
- James

Sent from Hyperspace.

On 03/12/2012, at 9:09 AM, Benoit St-Jean <[hidden email]> wrote:

> Is there a way to extend an existing class (say, Integer) without having to modify the core Integer.st file?  I want to add 2-3 methods to the Integer class but I'm wondering if there's a way to do so without modifying the "original" file?

Reply | Threaded
Open this post in threaded view
|

Re: Extending RedLine

Benoit St-Jean-4
Here's what I'm trying to add:
-----------------------------------------------------------------

Integer atSelector: #benchFib put: [
^ self < 2
        ifTrue: [1]
        ifFalse: [(self - 1) benchFib + (self - 2) benchFib + 1]
].

Integer atSelector: #benchmark put: [
 | size flags prime k count |
    size := 8190.
    1 to: self do:
        [:iter |
        count := 0.
        flags := (Array new: size) atAllPut: true.
        1 to: size do:
            [:i | (flags at: i) ifTrue:
                [prime := i + 1.
                k := i + prime.
                [k <= size] whileTrue:
                    [flags at: k put: false.
                    k := k + prime].
                count := count + 1]]].
    ^ count
].

Integer atSelector: #tinyBenchmarks put: [
    | t1 t2 r n1 n2 |
    n1 := 1.
    [t1 := Time millisecondsToRun: [n1 benchmark].
    t1 < 1000] whileTrue:[n1 := n1 * 2].

    n2 := 28.
    [t2 := Time millisecondsToRun: [r := n2 benchFib].
    t2 < 1000] whileTrue:[n2 := n2 + 1].
   
    ^ ((n1 * 500000 * 1000) // t1) printString, ' bytecodes/sec; ',
      ((r * 1000) // t2) printString, ' sends/sec'
].



-------------------------------------

I get the error:

line 26:9 mismatched input 'r' expecting '|'
line 27:4 mismatched input ':=' expecting ']'
line 27:7 missing EOF at '1'
Exception in thread "main" st.redline.core.RedlineException: Syntax error(s) detected
        at st.redline.core.RedlineException.withMessage(RedlineException.java:19)
        at st.redline.core.Kompiler.parse(Kompiler.java:51)
        at st.redline.core.Kompiler.compileSource(Kompiler.java:30)
        at st.redline.core.Kompiler.compile(Kompiler.java:26)
        at st.redline.core.SmalltalkSourceClassLoader.compile(SmalltalkSourceClassLoader.java:30)
        at st.redline.core.SmalltalkSourceClassLoader.classFrom(SmalltalkSourceClassLoader.java:21)
        at st.redline.core.SmalltalkSourceClassLoader.findClass(SmalltalkSourceClassLoader.java:17)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at st.redline.core.Stic.invoke(Stic.java:79)
        at st.redline.core.Stic.invokeWith(Stic.java:31)
        at st.redline.core.Stic.main(Stic.java:14)



On Sunday, 2 December 2012 20:34:52 UTC-5, jamesl wrote:
To extend an existing class in Redline Smalltalk requires you to send
a message to the class you want to extend to add a new method.

For example:

To add the instance method 'floor' to the Float class we send the
atSelector:put: message to the Float class -

Float atSelector: #floor put: [
   "code that does the floor math."
].

To add the class method 'random' to the Integer class we send the 
atSelector:put: message to the class of the Integer class -

Integer class atSelector: #random put: [
   "code that does the random generation."
].

The code inside the blocks is standard Smalltalk.

Arguments are catered for by adding arguments to the passed in block.
For example:

Integer class atSelector: #randomBetween:and: put: [ :low :hi |
   "code that does the random generation between low and hi."
].

Internally Redline sends these exact same messages when adding the methods
defined in a Class using the -/+.

For example, in class Object:

- yourself
  ^ self.

Becomes:

Object atSelector: #yourself put: [
    ^ self.
].

I hope this helps.

- James.

On Mon, Dec 3, 2012 at 9:36 AM, James Ladd <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ArdUvvsq79IJ">ladd....@...> wrote:
Of course, this is Smalltalk.

You need to send messages to the Integer class.
I'll post an example in two hours - travelling right now.
- James

Sent from Hyperspace.

On 03/12/2012, at 9:09 AM, Benoit St-Jean <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ArdUvvsq79IJ">benoit...@...> wrote:

> Is there a way to extend an existing class (say, Integer) without having to modify the core Integer.st file?  I want to add 2-3 methods to the Integer class but I'm wondering if there's a way to do so without modifying the "original" file?

Reply | Threaded
Open this post in threaded view
|

Re: Extending RedLine

James Ladd
There is an issue with ',' which I am looking into now.

The other issue Redline is giving with 'r' is related to how Redline needs to parse
numbers that can be in '<digits>r' - Renaming the 'r' in your example to r1 gets
you further.

I will look into the ',' issue.

On Mon, Dec 3, 2012 at 1:26 PM, Benoit St-Jean <[hidden email]> wrote:
Here's what I'm trying to add:
-----------------------------------------------------------------

Integer atSelector: #benchFib put: [
^ self < 2
        ifTrue: [1]
        ifFalse: [(self - 1) benchFib + (self - 2) benchFib + 1]
].

Integer atSelector: #benchmark put: [
 | size flags prime k count |
    size := 8190.
    1 to: self do:
        [:iter |
        count := 0.
        flags := (Array new: size) atAllPut: true.
        1 to: size do:
            [:i | (flags at: i) ifTrue:
                [prime := i + 1.
                k := i + prime.
                [k <= size] whileTrue:
                    [flags at: k put: false.
                    k := k + prime].
                count := count + 1]]].
    ^ count
].

Integer atSelector: #tinyBenchmarks put: [
    | t1 t2 r n1 n2 |
    n1 := 1.
    [t1 := Time millisecondsToRun: [n1 benchmark].
    t1 < 1000] whileTrue:[n1 := n1 * 2].

    n2 := 28.
    [t2 := Time millisecondsToRun: [r := n2 benchFib].
    t2 < 1000] whileTrue:[n2 := n2 + 1].
   
    ^ ((n1 * 500000 * 1000) // t1) printString, ' bytecodes/sec; ',
      ((r * 1000) // t2) printString, ' sends/sec'
].



-------------------------------------

I get the error:

line 26:9 mismatched input 'r' expecting '|'
line 27:4 mismatched input ':=' expecting ']'
line 27:7 missing EOF at '1'
Exception in thread "main" st.redline.core.RedlineException: Syntax error(s) detected
        at st.redline.core.RedlineException.withMessage(RedlineException.java:19)
        at st.redline.core.Kompiler.parse(Kompiler.java:51)
        at st.redline.core.Kompiler.compileSource(Kompiler.java:30)
        at st.redline.core.Kompiler.compile(Kompiler.java:26)
        at st.redline.core.SmalltalkSourceClassLoader.compile(SmalltalkSourceClassLoader.java:30)
        at st.redline.core.SmalltalkSourceClassLoader.classFrom(SmalltalkSourceClassLoader.java:21)
        at st.redline.core.SmalltalkSourceClassLoader.findClass(SmalltalkSourceClassLoader.java:17)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at st.redline.core.Stic.invoke(Stic.java:79)
        at st.redline.core.Stic.invokeWith(Stic.java:31)
        at st.redline.core.Stic.main(Stic.java:14)




On Sunday, 2 December 2012 20:34:52 UTC-5, jamesl wrote:
To extend an existing class in Redline Smalltalk requires you to send
a message to the class you want to extend to add a new method.

For example:

To add the instance method 'floor' to the Float class we send the
atSelector:put: message to the Float class -

Float atSelector: #floor put: [
   "code that does the floor math."
].

To add the class method 'random' to the Integer class we send the 
atSelector:put: message to the class of the Integer class -

Integer class atSelector: #random put: [
   "code that does the random generation."
].

The code inside the blocks is standard Smalltalk.

Arguments are catered for by adding arguments to the passed in block.
For example:

Integer class atSelector: #randomBetween:and: put: [ :low :hi |
   "code that does the random generation between low and hi."
].

Internally Redline sends these exact same messages when adding the methods
defined in a Class using the -/+.

For example, in class Object:

- yourself
  ^ self.

Becomes:

Object atSelector: #yourself put: [
    ^ self.
].

I hope this helps.

- James.

On Mon, Dec 3, 2012 at 9:36 AM, James Ladd <[hidden email]> wrote:
Of course, this is Smalltalk.

You need to send messages to the Integer class.
I'll post an example in two hours - travelling right now.
- James

Sent from Hyperspace.

On 03/12/2012, at 9:09 AM, Benoit St-Jean <[hidden email]> wrote:

> Is there a way to extend an existing class (say, Integer) without having to modify the core Integer.st file?  I want to add 2-3 methods to the Integer class but I'm wondering if there's a way to do so without modifying the "original" file?


Reply | Threaded
Open this post in threaded view
|

Re: Extending RedLine

Benoit St-Jean-4
By the way, there also seems to be a problem when some variables/pseudo-variables aren't separated by a space, such as in "(self-1)". It won't let me do it unless I rewrite it like "(self - 1)"

On Sunday, 2 December 2012 21:53:32 UTC-5, jamesl wrote:
There is an issue with ',' which I am looking into now.

The other issue Redline is giving with 'r' is related to how Redline needs to parse
numbers that can be in '<digits>r' - Renaming the 'r' in your example to r1 gets
you further.

I will look into the ',' issue.

On Mon, Dec 3, 2012 at 1:26 PM, Benoit St-Jean <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="NlonO8ww0OAJ">benoit...@...> wrote:
Here's what I'm trying to add:
-----------------------------------------------------------------

Integer atSelector: #benchFib put: [
^ self < 2
        ifTrue: [1]
        ifFalse: [(self - 1) benchFib + (self - 2) benchFib + 1]
].

Integer atSelector: #benchmark put: [
 | size flags prime k count |
    size := 8190.
    1 to: self do:
        [:iter |
        count := 0.
        flags := (Array new: size) atAllPut: true.
        1 to: size do:
            [:i | (flags at: i) ifTrue:
                [prime := i + 1.
                k := i + prime.
                [k <= size] whileTrue:
                    [flags at: k put: false.
                    k := k + prime].
                count := count + 1]]].
    ^ count
].

Integer atSelector: #tinyBenchmarks put: [
    | t1 t2 r n1 n2 |
    n1 := 1.
    [t1 := Time millisecondsToRun: [n1 benchmark].
    t1 < 1000] whileTrue:[n1 := n1 * 2].

    n2 := 28.
    [t2 := Time millisecondsToRun: [r := n2 benchFib].
    t2 < 1000] whileTrue:[n2 := n2 + 1].
   
    ^ ((n1 * 500000 * 1000) // t1) printString, ' bytecodes/sec; ',
      ((r * 1000) // t2) printString, ' sends/sec'
].



-------------------------------------

I get the error:

line 26:9 mismatched input 'r' expecting '|'
line 27:4 mismatched input ':=' expecting ']'
line 27:7 missing EOF at '1'
Exception in thread "main" st.redline.core.RedlineException: Syntax error(s) detected
        at st.redline.core.RedlineException.withMessage(RedlineException.java:19)
        at st.redline.core.Kompiler.parse(Kompiler.java:51)
        at st.redline.core.Kompiler.compileSource(Kompiler.java:30)
        at st.redline.core.Kompiler.compile(Kompiler.java:26)
        at st.redline.core.SmalltalkSourceClassLoader.compile(SmalltalkSourceClassLoader.java:30)
        at st.redline.core.SmalltalkSourceClassLoader.classFrom(SmalltalkSourceClassLoader.java:21)
        at st.redline.core.SmalltalkSourceClassLoader.findClass(SmalltalkSourceClassLoader.java:17)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at st.redline.core.Stic.invoke(Stic.java:79)
        at st.redline.core.Stic.invokeWith(Stic.java:31)
        at st.redline.core.Stic.main(Stic.java:14)




On Sunday, 2 December 2012 20:34:52 UTC-5, jamesl wrote:
To extend an existing class in Redline Smalltalk requires you to send
a message to the class you want to extend to add a new method.

For example:

To add the instance method 'floor' to the Float class we send the
atSelector:put: message to the Float class -

Float atSelector: #floor put: [
   "code that does the floor math."
].

To add the class method 'random' to the Integer class we send the 
atSelector:put: message to the class of the Integer class -

Integer class atSelector: #random put: [
   "code that does the random generation."
].

The code inside the blocks is standard Smalltalk.

Arguments are catered for by adding arguments to the passed in block.
For example:

Integer class atSelector: #randomBetween:and: put: [ :low :hi |
   "code that does the random generation between low and hi."
].

Internally Redline sends these exact same messages when adding the methods
defined in a Class using the -/+.

For example, in class Object:

- yourself
  ^ self.

Becomes:

Object atSelector: #yourself put: [
    ^ self.
].

I hope this helps.

- James.

On Mon, Dec 3, 2012 at 9:36 AM, James Ladd <[hidden email]> wrote:
Of course, this is Smalltalk.

You need to send messages to the Integer class.
I'll post an example in two hours - travelling right now.
- James

Sent from Hyperspace.

On 03/12/2012, at 9:09 AM, Benoit St-Jean <[hidden email]> wrote:

> Is there a way to extend an existing class (say, Integer) without having to modify the core Integer.st file?  I want to add 2-3 methods to the Integer class but I'm wondering if there's a way to do so without modifying the "original" file?


Reply | Threaded
Open this post in threaded view
|

Re: Extending RedLine

James Ladd
In reply to this post by James Ladd
I tried the following example which works as expected:

| a b c |
a := 'foo'.
b := 'bar'.
c := a , b.

This results in the following expected Exception:

Exception in thread "main" st.redline.core.RedlineException: Object 'foo' (String) does not understand ',' with arguments:
1    bar

Your example parse fine when a space precedes ',' like this:

^ ((n1 * 500000 * 1000) // t1) printString , ' bytecodes/sec; ' , ((r1 * 1000) // t2) printString , ' sends/sec'.

This will allow you to continue without modification to Redline. I'll raise an issue about requiring the space.

On Mon, Dec 3, 2012 at 1:53 PM, James Ladd <[hidden email]> wrote:
There is an issue with ',' which I am looking into now.

The other issue Redline is giving with 'r' is related to how Redline needs to parse
numbers that can be in '<digits>r' - Renaming the 'r' in your example to r1 gets
you further.

I will look into the ',' issue.


On Mon, Dec 3, 2012 at 1:26 PM, Benoit St-Jean <[hidden email]> wrote:
Here's what I'm trying to add:
-----------------------------------------------------------------

Integer atSelector: #benchFib put: [
^ self < 2
        ifTrue: [1]
        ifFalse: [(self - 1) benchFib + (self - 2) benchFib + 1]
].

Integer atSelector: #benchmark put: [
 | size flags prime k count |
    size := 8190.
    1 to: self do:
        [:iter |
        count := 0.
        flags := (Array new: size) atAllPut: true.
        1 to: size do:
            [:i | (flags at: i) ifTrue:
                [prime := i + 1.
                k := i + prime.
                [k <= size] whileTrue:
                    [flags at: k put: false.
                    k := k + prime].
                count := count + 1]]].
    ^ count
].

Integer atSelector: #tinyBenchmarks put: [
    | t1 t2 r n1 n2 |
    n1 := 1.
    [t1 := Time millisecondsToRun: [n1 benchmark].
    t1 < 1000] whileTrue:[n1 := n1 * 2].

    n2 := 28.
    [t2 := Time millisecondsToRun: [r := n2 benchFib].
    t2 < 1000] whileTrue:[n2 := n2 + 1].
   
    ^ ((n1 * 500000 * 1000) // t1) printString, ' bytecodes/sec; ',
      ((r * 1000) // t2) printString, ' sends/sec'
].



-------------------------------------

I get the error:

line 26:9 mismatched input 'r' expecting '|'
line 27:4 mismatched input ':=' expecting ']'
line 27:7 missing EOF at '1'
Exception in thread "main" st.redline.core.RedlineException: Syntax error(s) detected
        at st.redline.core.RedlineException.withMessage(RedlineException.java:19)
        at st.redline.core.Kompiler.parse(Kompiler.java:51)
        at st.redline.core.Kompiler.compileSource(Kompiler.java:30)
        at st.redline.core.Kompiler.compile(Kompiler.java:26)
        at st.redline.core.SmalltalkSourceClassLoader.compile(SmalltalkSourceClassLoader.java:30)
        at st.redline.core.SmalltalkSourceClassLoader.classFrom(SmalltalkSourceClassLoader.java:21)
        at st.redline.core.SmalltalkSourceClassLoader.findClass(SmalltalkSourceClassLoader.java:17)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at st.redline.core.Stic.invoke(Stic.java:79)
        at st.redline.core.Stic.invokeWith(Stic.java:31)
        at st.redline.core.Stic.main(Stic.java:14)




On Sunday, 2 December 2012 20:34:52 UTC-5, jamesl wrote:
To extend an existing class in Redline Smalltalk requires you to send
a message to the class you want to extend to add a new method.

For example:

To add the instance method 'floor' to the Float class we send the
atSelector:put: message to the Float class -

Float atSelector: #floor put: [
   "code that does the floor math."
].

To add the class method 'random' to the Integer class we send the 
atSelector:put: message to the class of the Integer class -

Integer class atSelector: #random put: [
   "code that does the random generation."
].

The code inside the blocks is standard Smalltalk.

Arguments are catered for by adding arguments to the passed in block.
For example:

Integer class atSelector: #randomBetween:and: put: [ :low :hi |
   "code that does the random generation between low and hi."
].

Internally Redline sends these exact same messages when adding the methods
defined in a Class using the -/+.

For example, in class Object:

- yourself
  ^ self.

Becomes:

Object atSelector: #yourself put: [
    ^ self.
].

I hope this helps.

- James.

On Mon, Dec 3, 2012 at 9:36 AM, James Ladd <[hidden email]> wrote:
Of course, this is Smalltalk.

You need to send messages to the Integer class.
I'll post an example in two hours - travelling right now.
- James

Sent from Hyperspace.

On 03/12/2012, at 9:09 AM, Benoit St-Jean <[hidden email]> wrote:

> Is there a way to extend an existing class (say, Integer) without having to modify the core Integer.st file?  I want to add 2-3 methods to the Integer class but I'm wondering if there's a way to do so without modifying the "original" file?



Reply | Threaded
Open this post in threaded view
|

Re: Extending RedLine

Benoit St-Jean-4
Yep, I made another step!  But now, Time>>#millisecondsToRun: isn<t implemented in class Time.  The .st file show that the Time class is empty.  I guess my question now becomes what do I have to do to complete/code it and do you have a list of primitives so I can determine what I have to use to start extending the Time class?

On Sunday, 2 December 2012 22:32:56 UTC-5, jamesl wrote:
I tried the following example which works as expected:

| a b c |
a := 'foo'.
b := 'bar'.
c := a , b.

This results in the following expected Exception:

Exception in thread "main" st.redline.core.RedlineException: Object 'foo' (String) does not understand ',' with arguments:
1    bar

Your example parse fine when a space precedes ',' like this:

^ ((n1 * 500000 * 1000) // t1) printString , ' bytecodes/sec; ' , ((r1 * 1000) // t2) printString , ' sends/sec'.

This will allow you to continue without modification to Redline. I'll raise an issue about requiring the space.

On Mon, Dec 3, 2012 at 1:53 PM, James Ladd <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="JAfB2ZnNEuQJ">ladd....@...> wrote:
There is an issue with ',' which I am looking into now.

The other issue Redline is giving with 'r' is related to how Redline needs to parse
numbers that can be in '<digits>r' - Renaming the 'r' in your example to r1 gets
you further.

I will look into the ',' issue.


On Mon, Dec 3, 2012 at 1:26 PM, Benoit St-Jean <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="JAfB2ZnNEuQJ">benoit...@...> wrote:
Here's what I'm trying to add:
-----------------------------------------------------------------

Integer atSelector: #benchFib put: [
^ self < 2
        ifTrue: [1]
        ifFalse: [(self - 1) benchFib + (self - 2) benchFib + 1]
].

Integer atSelector: #benchmark put: [
 | size flags prime k count |
    size := 8190.
    1 to: self do:
        [:iter |
        count := 0.
        flags := (Array new: size) atAllPut: true.
        1 to: size do:
            [:i | (flags at: i) ifTrue:
                [prime := i + 1.
                k := i + prime.
                [k <= size] whileTrue:
                    [flags at: k put: false.
                    k := k + prime].
                count := count + 1]]].
    ^ count
].

Integer atSelector: #tinyBenchmarks put: [
    | t1 t2 r n1 n2 |
    n1 := 1.
    [t1 := Time millisecondsToRun: [n1 benchmark].
    t1 < 1000] whileTrue:[n1 := n1 * 2].

    n2 := 28.
    [t2 := Time millisecondsToRun: [r := n2 benchFib].
    t2 < 1000] whileTrue:[n2 := n2 + 1].
   
    ^ ((n1 * 500000 * 1000) // t1) printString, ' bytecodes/sec; ',
      ((r * 1000) // t2) printString, ' sends/sec'
].



-------------------------------------

I get the error:

line 26:9 mismatched input 'r' expecting '|'
line 27:4 mismatched input ':=' expecting ']'
line 27:7 missing EOF at '1'
Exception in thread "main" st.redline.core.RedlineException: Syntax error(s) detected
        at st.redline.core.RedlineException.withMessage(RedlineException.java:19)
        at st.redline.core.Kompiler.parse(Kompiler.java:51)
        at st.redline.core.Kompiler.compileSource(Kompiler.java:30)
        at st.redline.core.Kompiler.compile(Kompiler.java:26)
        at st.redline.core.SmalltalkSourceClassLoader.compile(SmalltalkSourceClassLoader.java:30)
        at st.redline.core.SmalltalkSourceClassLoader.classFrom(SmalltalkSourceClassLoader.java:21)
        at st.redline.core.SmalltalkSourceClassLoader.findClass(SmalltalkSourceClassLoader.java:17)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at st.redline.core.Stic.invoke(Stic.java:79)
        at st.redline.core.Stic.invokeWith(Stic.java:31)
        at st.redline.core.Stic.main(Stic.java:14)




On Sunday, 2 December 2012 20:34:52 UTC-5, jamesl wrote:
To extend an existing class in Redline Smalltalk requires you to send
a message to the class you want to extend to add a new method.

For example:

To add the instance method 'floor' to the Float class we send the
atSelector:put: message to the Float class -

Float atSelector: #floor put: [
   "code that does the floor math."
].

To add the class method 'random' to the Integer class we send the 
atSelector:put: message to the class of the Integer class -

Integer class atSelector: #random put: [
   "code that does the random generation."
].

The code inside the blocks is standard Smalltalk.

Arguments are catered for by adding arguments to the passed in block.
For example:

Integer class atSelector: #randomBetween:and: put: [ :low :hi |
   "code that does the random generation between low and hi."
].

Internally Redline sends these exact same messages when adding the methods
defined in a Class using the -/+.

For example, in class Object:

- yourself
  ^ self.

Becomes:

Object atSelector: #yourself put: [
    ^ self.
].

I hope this helps.

- James.

On Mon, Dec 3, 2012 at 9:36 AM, James Ladd <[hidden email]> wrote:
Of course, this is Smalltalk.

You need to send messages to the Integer class.
I'll post an example in two hours - travelling right now.
- James

Sent from Hyperspace.

On 03/12/2012, at 9:09 AM, Benoit St-Jean <[hidden email]> wrote:

> Is there a way to extend an existing class (say, Integer) without having to modify the core Integer.st file?  I want to add 2-3 methods to the Integer class but I'm wondering if there's a way to do so without modifying the "original" file?



Reply | Threaded
Open this post in threaded view
|

Re: Extending RedLine

James Ladd
Hi Benoit,

We would more than welcome you implementing the class.

To do this you should fork the Redline Smalltalk github repo,
then ensure that you can build it and run an example class.
You may need to implement a primitive or have a look at one
or two, hence the need to see the source code etc.
Instructions for building the source and testing Redline is
working is found in The <a href="http://Quick Start - From sources">Getting Started with Redline Smalltalk
page, Quick Start from the sources section.

You should then follow the implementation of the Time class in
Pharo and port it across to Redline. You may find there are other
classes you will need to port as well depending on the implementation
of Time.

PLEASE write a test around the class. You can see these in the sources.
I'm porting SUinit now but we have a way of testing right now.
Accepting a port is made a LOT easier with supporting tests.

What you are doing is essentially the same thing I will be doing when
the Redline Smalltalk Campaign is over, that is, implementing the full
runtime.

For a primitive you will need to look at the Java methods in PrimObject
that are in the form p<number> - These are primitives. However, to implement
a primitive takes some understanding of the innards of the compiler and
java objects that back the Smalltalk objects, so you might want to call on
us to help you when the time comes.  I'll try and have a quick look today to
see the primitives required.

Good Luck!

- James.

On Mon, Dec 3, 2012 at 11:16 PM, Benoit St-Jean <[hidden email]> wrote:
Yep, I made another step!  But now, Time>>#millisecondsToRun: isn<t implemented in class Time.  The .st file show that the Time class is empty.  I guess my question now becomes what do I have to do to complete/code it and do you have a list of primitives so I can determine what I have to use to start extending the Time class?


On Sunday, 2 December 2012 22:32:56 UTC-5, jamesl wrote:
I tried the following example which works as expected:

| a b c |
a := 'foo'.
b := 'bar'.
c := a , b.

This results in the following expected Exception:

Exception in thread "main" st.redline.core.RedlineException: Object 'foo' (String) does not understand ',' with arguments:
1    bar

Your example parse fine when a space precedes ',' like this:

^ ((n1 * 500000 * 1000) // t1) printString , ' bytecodes/sec; ' , ((r1 * 1000) // t2) printString , ' sends/sec'.

This will allow you to continue without modification to Redline. I'll raise an issue about requiring the space.

On Mon, Dec 3, 2012 at 1:53 PM, James Ladd <[hidden email]> wrote:
There is an issue with ',' which I am looking into now.

The other issue Redline is giving with 'r' is related to how Redline needs to parse
numbers that can be in '<digits>r' - Renaming the 'r' in your example to r1 gets
you further.

I will look into the ',' issue.


On Mon, Dec 3, 2012 at 1:26 PM, Benoit St-Jean <[hidden email]> wrote:
Here's what I'm trying to add:
-----------------------------------------------------------------

Integer atSelector: #benchFib put: [
^ self < 2
        ifTrue: [1]
        ifFalse: [(self - 1) benchFib + (self - 2) benchFib + 1]
].

Integer atSelector: #benchmark put: [
 | size flags prime k count |
    size := 8190.
    1 to: self do:
        [:iter |
        count := 0.
        flags := (Array new: size) atAllPut: true.
        1 to: size do:
            [:i | (flags at: i) ifTrue:
                [prime := i + 1.
                k := i + prime.
                [k <= size] whileTrue:
                    [flags at: k put: false.
                    k := k + prime].
                count := count + 1]]].
    ^ count
].

Integer atSelector: #tinyBenchmarks put: [
    | t1 t2 r n1 n2 |
    n1 := 1.
    [t1 := Time millisecondsToRun: [n1 benchmark].
    t1 < 1000] whileTrue:[n1 := n1 * 2].

    n2 := 28.
    [t2 := Time millisecondsToRun: [r := n2 benchFib].
    t2 < 1000] whileTrue:[n2 := n2 + 1].
   
    ^ ((n1 * 500000 * 1000) // t1) printString, ' bytecodes/sec; ',
      ((r * 1000) // t2) printString, ' sends/sec'
].



-------------------------------------

I get the error:

line 26:9 mismatched input 'r' expecting '|'
line 27:4 mismatched input ':=' expecting ']'
line 27:7 missing EOF at '1'
Exception in thread "main" st.redline.core.RedlineException: Syntax error(s) detected
        at st.redline.core.RedlineException.withMessage(RedlineException.java:19)
        at st.redline.core.Kompiler.parse(Kompiler.java:51)
        at st.redline.core.Kompiler.compileSource(Kompiler.java:30)
        at st.redline.core.Kompiler.compile(Kompiler.java:26)
        at st.redline.core.SmalltalkSourceClassLoader.compile(SmalltalkSourceClassLoader.java:30)
        at st.redline.core.SmalltalkSourceClassLoader.classFrom(SmalltalkSourceClassLoader.java:21)
        at st.redline.core.SmalltalkSourceClassLoader.findClass(SmalltalkSourceClassLoader.java:17)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at st.redline.core.Stic.invoke(Stic.java:79)
        at st.redline.core.Stic.invokeWith(Stic.java:31)
        at st.redline.core.Stic.main(Stic.java:14)




On Sunday, 2 December 2012 20:34:52 UTC-5, jamesl wrote:
To extend an existing class in Redline Smalltalk requires you to send
a message to the class you want to extend to add a new method.

For example:

To add the instance method 'floor' to the Float class we send the
atSelector:put: message to the Float class -

Float atSelector: #floor put: [
   "code that does the floor math."
].

To add the class method 'random' to the Integer class we send the 
atSelector:put: message to the class of the Integer class -

Integer class atSelector: #random put: [
   "code that does the random generation."
].

The code inside the blocks is standard Smalltalk.

Arguments are catered for by adding arguments to the passed in block.
For example:

Integer class atSelector: #randomBetween:and: put: [ :low :hi |
   "code that does the random generation between low and hi."
].

Internally Redline sends these exact same messages when adding the methods
defined in a Class using the -/+.

For example, in class Object:

- yourself
  ^ self.

Becomes:

Object atSelector: #yourself put: [
    ^ self.
].

I hope this helps.

- James.

On Mon, Dec 3, 2012 at 9:36 AM, James Ladd <[hidden email]> wrote:
Of course, this is Smalltalk.

You need to send messages to the Integer class.
I'll post an example in two hours - travelling right now.
- James

Sent from Hyperspace.

On 03/12/2012, at 9:09 AM, Benoit St-Jean <[hidden email]> wrote:

> Is there a way to extend an existing class (say, Integer) without having to modify the core Integer.st file?  I want to add 2-3 methods to the Integer class but I'm wondering if there's a way to do so without modifying the "original" file?




Reply | Threaded
Open this post in threaded view
|

Re: Extending RedLine

Steve Wart-2
What's the best practice for implementing these classes? Would you rather see a Smalltalk wrapper around equivalent Java functionality, or new Smalltalk classes built from scratch?

I'd argue for the former, but "equivalency" could prove to be sticky...


On Mon, Dec 3, 2012 at 12:39 PM, James Ladd <[hidden email]> wrote:
Hi Benoit,

We would more than welcome you implementing the class.

To do this you should fork the Redline Smalltalk github repo,
then ensure that you can build it and run an example class.
You may need to implement a primitive or have a look at one
or two, hence the need to see the source code etc.
Instructions for building the source and testing Redline is
working is found in The Getting Started with Redline Smalltalk
page, Quick Start from the sources section.

You should then follow the implementation of the Time class in
Pharo and port it across to Redline. You may find there are other
classes you will need to port as well depending on the implementation
of Time.

PLEASE write a test around the class. You can see these in the sources.
I'm porting SUinit now but we have a way of testing right now.
Accepting a port is made a LOT easier with supporting tests.

What you are doing is essentially the same thing I will be doing when
the Redline Smalltalk Campaign is over, that is, implementing the full
runtime.

For a primitive you will need to look at the Java methods in PrimObject
that are in the form p<number> - These are primitives. However, to implement
a primitive takes some understanding of the innards of the compiler and
java objects that back the Smalltalk objects, so you might want to call on
us to help you when the time comes.  I'll try and have a quick look today to
see the primitives required.

Good Luck!

- James.


On Mon, Dec 3, 2012 at 11:16 PM, Benoit St-Jean <[hidden email]> wrote:
Yep, I made another step!  But now, Time>>#millisecondsToRun: isn<t implemented in class Time.  The .st file show that the Time class is empty.  I guess my question now becomes what do I have to do to complete/code it and do you have a list of primitives so I can determine what I have to use to start extending the Time class?


On Sunday, 2 December 2012 22:32:56 UTC-5, jamesl wrote:
I tried the following example which works as expected:

| a b c |
a := 'foo'.
b := 'bar'.
c := a , b.

This results in the following expected Exception:

Exception in thread "main" st.redline.core.RedlineException: Object 'foo' (String) does not understand ',' with arguments:
1    bar

Your example parse fine when a space precedes ',' like this:

^ ((n1 * 500000 * 1000) // t1) printString , ' bytecodes/sec; ' , ((r1 * 1000) // t2) printString , ' sends/sec'.

This will allow you to continue without modification to Redline. I'll raise an issue about requiring the space.

On Mon, Dec 3, 2012 at 1:53 PM, James Ladd <[hidden email]> wrote:
There is an issue with ',' which I am looking into now.

The other issue Redline is giving with 'r' is related to how Redline needs to parse
numbers that can be in '<digits>r' - Renaming the 'r' in your example to r1 gets
you further.

I will look into the ',' issue.


On Mon, Dec 3, 2012 at 1:26 PM, Benoit St-Jean <[hidden email]> wrote:
Here's what I'm trying to add:
-----------------------------------------------------------------

Integer atSelector: #benchFib put: [
^ self < 2
        ifTrue: [1]
        ifFalse: [(self - 1) benchFib + (self - 2) benchFib + 1]
].

Integer atSelector: #benchmark put: [
 | size flags prime k count |
    size := 8190.
    1 to: self do:
        [:iter |
        count := 0.
        flags := (Array new: size) atAllPut: true.
        1 to: size do:
            [:i | (flags at: i) ifTrue:
                [prime := i + 1.
                k := i + prime.
                [k <= size] whileTrue:
                    [flags at: k put: false.
                    k := k + prime].
                count := count + 1]]].
    ^ count
].

Integer atSelector: #tinyBenchmarks put: [
    | t1 t2 r n1 n2 |
    n1 := 1.
    [t1 := Time millisecondsToRun: [n1 benchmark].
    t1 < 1000] whileTrue:[n1 := n1 * 2].

    n2 := 28.
    [t2 := Time millisecondsToRun: [r := n2 benchFib].
    t2 < 1000] whileTrue:[n2 := n2 + 1].
   
    ^ ((n1 * 500000 * 1000) // t1) printString, ' bytecodes/sec; ',
      ((r * 1000) // t2) printString, ' sends/sec'
].



-------------------------------------

I get the error:

line 26:9 mismatched input 'r' expecting '|'
line 27:4 mismatched input ':=' expecting ']'
line 27:7 missing EOF at '1'
Exception in thread "main" st.redline.core.RedlineException: Syntax error(s) detected
        at st.redline.core.RedlineException.withMessage(RedlineException.java:19)
        at st.redline.core.Kompiler.parse(Kompiler.java:51)
        at st.redline.core.Kompiler.compileSource(Kompiler.java:30)
        at st.redline.core.Kompiler.compile(Kompiler.java:26)
        at st.redline.core.SmalltalkSourceClassLoader.compile(SmalltalkSourceClassLoader.java:30)
        at st.redline.core.SmalltalkSourceClassLoader.classFrom(SmalltalkSourceClassLoader.java:21)
        at st.redline.core.SmalltalkSourceClassLoader.findClass(SmalltalkSourceClassLoader.java:17)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at st.redline.core.Stic.invoke(Stic.java:79)
        at st.redline.core.Stic.invokeWith(Stic.java:31)
        at st.redline.core.Stic.main(Stic.java:14)




On Sunday, 2 December 2012 20:34:52 UTC-5, jamesl wrote:
To extend an existing class in Redline Smalltalk requires you to send
a message to the class you want to extend to add a new method.

For example:

To add the instance method 'floor' to the Float class we send the
atSelector:put: message to the Float class -

Float atSelector: #floor put: [
   "code that does the floor math."
].

To add the class method 'random' to the Integer class we send the 
atSelector:put: message to the class of the Integer class -

Integer class atSelector: #random put: [
   "code that does the random generation."
].

The code inside the blocks is standard Smalltalk.

Arguments are catered for by adding arguments to the passed in block.
For example:

Integer class atSelector: #randomBetween:and: put: [ :low :hi |
   "code that does the random generation between low and hi."
].

Internally Redline sends these exact same messages when adding the methods
defined in a Class using the -/+.

For example, in class Object:

- yourself
  ^ self.

Becomes:

Object atSelector: #yourself put: [
    ^ self.
].

I hope this helps.

- James.

On Mon, Dec 3, 2012 at 9:36 AM, James Ladd <[hidden email]> wrote:
Of course, this is Smalltalk.

You need to send messages to the Integer class.
I'll post an example in two hours - travelling right now.
- James

Sent from Hyperspace.

On 03/12/2012, at 9:09 AM, Benoit St-Jean <[hidden email]> wrote:

> Is there a way to extend an existing class (say, Integer) without having to modify the core Integer.st file?  I want to add 2-3 methods to the Integer class but I'm wondering if there's a way to do so without modifying the "original" file?





Reply | Threaded
Open this post in threaded view
|

Re: Extending RedLine

James Ladd
A very good question.

Redline is first and foremost a Smalltalk, and secondly handy for talking to Java classes.
Therefore, I would like to see classes provide the functionality of their equivalent in Pharo.
If during their implementation they can wrap or use Java then Redline makes this easy.
To reiterate - First Smalltalk, second Java.

For example, Time should be a port of the Pharo Time class, with only the primitives implemented
in Java. This approach also ensures that as Redline progresses with the implementation of the
Runtime the underlying classes provide those primitives needed by all classes consistently.

Please let me know if this is not clear.

- James.

On Tue, Dec 4, 2012 at 8:08 AM, Steve Wart <[hidden email]> wrote:
What's the best practice for implementing these classes? Would you rather see a Smalltalk wrapper around equivalent Java functionality, or new Smalltalk classes built from scratch?

I'd argue for the former, but "equivalency" could prove to be sticky...



On Mon, Dec 3, 2012 at 12:39 PM, James Ladd <[hidden email]> wrote:
Hi Benoit,

We would more than welcome you implementing the class.

To do this you should fork the Redline Smalltalk github repo,
then ensure that you can build it and run an example class.
You may need to implement a primitive or have a look at one
or two, hence the need to see the source code etc.
Instructions for building the source and testing Redline is
working is found in The Getting Started with Redline Smalltalk
page, Quick Start from the sources section.

You should then follow the implementation of the Time class in
Pharo and port it across to Redline. You may find there are other
classes you will need to port as well depending on the implementation
of Time.

PLEASE write a test around the class. You can see these in the sources.
I'm porting SUinit now but we have a way of testing right now.
Accepting a port is made a LOT easier with supporting tests.

What you are doing is essentially the same thing I will be doing when
the Redline Smalltalk Campaign is over, that is, implementing the full
runtime.

For a primitive you will need to look at the Java methods in PrimObject
that are in the form p<number> - These are primitives. However, to implement
a primitive takes some understanding of the innards of the compiler and
java objects that back the Smalltalk objects, so you might want to call on
us to help you when the time comes.  I'll try and have a quick look today to
see the primitives required.

Good Luck!

- James.


On Mon, Dec 3, 2012 at 11:16 PM, Benoit St-Jean <[hidden email]> wrote:
Yep, I made another step!  But now, Time>>#millisecondsToRun: isn<t implemented in class Time.  The .st file show that the Time class is empty.  I guess my question now becomes what do I have to do to complete/code it and do you have a list of primitives so I can determine what I have to use to start extending the Time class?


On Sunday, 2 December 2012 22:32:56 UTC-5, jamesl wrote:
I tried the following example which works as expected:

| a b c |
a := 'foo'.
b := 'bar'.
c := a , b.

This results in the following expected Exception:

Exception in thread "main" st.redline.core.RedlineException: Object 'foo' (String) does not understand ',' with arguments:
1    bar

Your example parse fine when a space precedes ',' like this:

^ ((n1 * 500000 * 1000) // t1) printString , ' bytecodes/sec; ' , ((r1 * 1000) // t2) printString , ' sends/sec'.

This will allow you to continue without modification to Redline. I'll raise an issue about requiring the space.

On Mon, Dec 3, 2012 at 1:53 PM, James Ladd <[hidden email]> wrote:
There is an issue with ',' which I am looking into now.

The other issue Redline is giving with 'r' is related to how Redline needs to parse
numbers that can be in '<digits>r' - Renaming the 'r' in your example to r1 gets
you further.

I will look into the ',' issue.


On Mon, Dec 3, 2012 at 1:26 PM, Benoit St-Jean <[hidden email]> wrote:
Here's what I'm trying to add:
-----------------------------------------------------------------

Integer atSelector: #benchFib put: [
^ self < 2
        ifTrue: [1]
        ifFalse: [(self - 1) benchFib + (self - 2) benchFib + 1]
].

Integer atSelector: #benchmark put: [
 | size flags prime k count |
    size := 8190.
    1 to: self do:
        [:iter |
        count := 0.
        flags := (Array new: size) atAllPut: true.
        1 to: size do:
            [:i | (flags at: i) ifTrue:
                [prime := i + 1.
                k := i + prime.
                [k <= size] whileTrue:
                    [flags at: k put: false.
                    k := k + prime].
                count := count + 1]]].
    ^ count
].

Integer atSelector: #tinyBenchmarks put: [
    | t1 t2 r n1 n2 |
    n1 := 1.
    [t1 := Time millisecondsToRun: [n1 benchmark].
    t1 < 1000] whileTrue:[n1 := n1 * 2].

    n2 := 28.
    [t2 := Time millisecondsToRun: [r := n2 benchFib].
    t2 < 1000] whileTrue:[n2 := n2 + 1].
   
    ^ ((n1 * 500000 * 1000) // t1) printString, ' bytecodes/sec; ',
      ((r * 1000) // t2) printString, ' sends/sec'
].



-------------------------------------

I get the error:

line 26:9 mismatched input 'r' expecting '|'
line 27:4 mismatched input ':=' expecting ']'
line 27:7 missing EOF at '1'
Exception in thread "main" st.redline.core.RedlineException: Syntax error(s) detected
        at st.redline.core.RedlineException.withMessage(RedlineException.java:19)
        at st.redline.core.Kompiler.parse(Kompiler.java:51)
        at st.redline.core.Kompiler.compileSource(Kompiler.java:30)
        at st.redline.core.Kompiler.compile(Kompiler.java:26)
        at st.redline.core.SmalltalkSourceClassLoader.compile(SmalltalkSourceClassLoader.java:30)
        at st.redline.core.SmalltalkSourceClassLoader.classFrom(SmalltalkSourceClassLoader.java:21)
        at st.redline.core.SmalltalkSourceClassLoader.findClass(SmalltalkSourceClassLoader.java:17)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at st.redline.core.Stic.invoke(Stic.java:79)
        at st.redline.core.Stic.invokeWith(Stic.java:31)
        at st.redline.core.Stic.main(Stic.java:14)




On Sunday, 2 December 2012 20:34:52 UTC-5, jamesl wrote:
To extend an existing class in Redline Smalltalk requires you to send
a message to the class you want to extend to add a new method.

For example:

To add the instance method 'floor' to the Float class we send the
atSelector:put: message to the Float class -

Float atSelector: #floor put: [
   "code that does the floor math."
].

To add the class method 'random' to the Integer class we send the 
atSelector:put: message to the class of the Integer class -

Integer class atSelector: #random put: [
   "code that does the random generation."
].

The code inside the blocks is standard Smalltalk.

Arguments are catered for by adding arguments to the passed in block.
For example:

Integer class atSelector: #randomBetween:and: put: [ :low :hi |
   "code that does the random generation between low and hi."
].

Internally Redline sends these exact same messages when adding the methods
defined in a Class using the -/+.

For example, in class Object:

- yourself
  ^ self.

Becomes:

Object atSelector: #yourself put: [
    ^ self.
].

I hope this helps.

- James.

On Mon, Dec 3, 2012 at 9:36 AM, James Ladd <[hidden email]> wrote:
Of course, this is Smalltalk.

You need to send messages to the Integer class.
I'll post an example in two hours - travelling right now.
- James

Sent from Hyperspace.

On 03/12/2012, at 9:09 AM, Benoit St-Jean <[hidden email]> wrote:

> Is there a way to extend an existing class (say, Integer) without having to modify the core Integer.st file?  I want to add 2-3 methods to the Integer class but I'm wondering if there's a way to do so without modifying the "original" file?






Reply | Threaded
Open this post in threaded view
|

Re: Extending RedLine

Benoit St-Jean-4
To add my 2 cents, the way I see it is to have most of the stuff done in Smalltalk and use Java for the primitives, the same way all Smalltalk VM have been implemented...

If need be, later, we could provide new primitives/wrappers if we ever need to boost performance in very specific areas...


On Monday, 3 December 2012 16:19:42 UTC-5, jamesl wrote:
A very good question.

Redline is first and foremost a Smalltalk, and secondly handy for talking to Java classes.
Therefore, I would like to see classes provide the functionality of their equivalent in Pharo.
If during their implementation they can wrap or use Java then Redline makes this easy.
To reiterate - First Smalltalk, second Java.

For example, Time should be a port of the Pharo Time class, with only the primitives implemented
in Java. This approach also ensures that as Redline progresses with the implementation of the
Runtime the underlying classes provide those primitives needed by all classes consistently.

Please let me know if this is not clear.

- James.

On Tue, Dec 4, 2012 at 8:08 AM, Steve Wart <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="mKdrpQsGyBsJ">st...@...> wrote:
What's the best practice for implementing these classes? Would you rather see a Smalltalk wrapper around equivalent Java functionality, or new Smalltalk classes built from scratch?

I'd argue for the former, but "equivalency" could prove to be sticky...



On Mon, Dec 3, 2012 at 12:39 PM, James Ladd <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="mKdrpQsGyBsJ">ladd....@...> wrote:
Hi Benoit,

We would more than welcome you implementing the class.

To do this you should fork the Redline Smalltalk github repo,
then ensure that you can build it and run an example class.
You may need to implement a primitive or have a look at one
or two, hence the need to see the source code etc.
Instructions for building the source and testing Redline is
working is found in The Getting Started with Redline Smalltalk
page, Quick Start from the sources section.

You should then follow the implementation of the Time class in
Pharo and port it across to Redline. You may find there are other
classes you will need to port as well depending on the implementation
of Time.

PLEASE write a test around the class. You can see these in the sources.
I'm porting SUinit now but we have a way of testing right now.
Accepting a port is made a LOT easier with supporting tests.

What you are doing is essentially the same thing I will be doing when
the Redline Smalltalk Campaign is over, that is, implementing the full
runtime.

For a primitive you will need to look at the Java methods in PrimObject
that are in the form p<number> - These are primitives. However, to implement
a primitive takes some understanding of the innards of the compiler and
java objects that back the Smalltalk objects, so you might want to call on
us to help you when the time comes.  I'll try and have a quick look today to
see the primitives required.

Good Luck!

- James.


On Mon, Dec 3, 2012 at 11:16 PM, Benoit St-Jean <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="mKdrpQsGyBsJ">benoit...@...> wrote:
Yep, I made another step!  But now, Time>>#millisecondsToRun: isn<t implemented in class Time.  The .st file show that the Time class is empty.  I guess my question now becomes what do I have to do to complete/code it and do you have a list of primitives so I can determine what I have to use to start extending the Time class?


On Sunday, 2 December 2012 22:32:56 UTC-5, jamesl wrote:
I tried the following example which works as expected:

| a b c |
a := 'foo'.
b := 'bar'.
c := a , b.

This results in the following expected Exception:

Exception in thread "main" st.redline.core.RedlineException: Object 'foo' (String) does not understand ',' with arguments:
1    bar

Your example parse fine when a space precedes ',' like this:

^ ((n1 * 500000 * 1000) // t1) printString , ' bytecodes/sec; ' , ((r1 * 1000) // t2) printString , ' sends/sec'.

This will allow you to continue without modification to Redline. I'll raise an issue about requiring the space.

On Mon, Dec 3, 2012 at 1:53 PM, James Ladd <[hidden email]> wrote:
There is an issue with ',' which I am looking into now.

The other issue Redline is giving with 'r' is related to how Redline needs to parse
numbers that can be in '<digits>r' - Renaming the 'r' in your example to r1 gets
you further.

I will look into the ',' issue.


On Mon, Dec 3, 2012 at 1:26 PM, Benoit St-Jean <[hidden email]> wrote:
Here's what I'm trying to add:
-----------------------------------------------------------------

Integer atSelector: #benchFib put: [
^ self < 2
        ifTrue: [1]
        ifFalse: [(self - 1) benchFib + (self - 2) benchFib + 1]
].

Integer atSelector: #benchmark put: [
 | size flags prime k count |
    size := 8190.
    1 to: self do:
        [:iter |
        count := 0.
        flags := (Array new: size) atAllPut: true.
        1 to: size do:
            [:i | (flags at: i) ifTrue:
                [prime := i + 1.
                k := i + prime.
                [k <= size] whileTrue:
                    [flags at: k put: false.
                    k := k + prime].
                count := count + 1]]].
    ^ count
].

Integer atSelector: #tinyBenchmarks put: [
    | t1 t2 r n1 n2 |
    n1 := 1.
    [t1 := Time millisecondsToRun: [n1 benchmark].
    t1 < 1000] whileTrue:[n1 := n1 * 2].

    n2 := 28.
    [t2 := Time millisecondsToRun: [r := n2 benchFib].
    t2 < 1000] whileTrue:[n2 := n2 + 1].
   
    ^ ((n1 * 500000 * 1000) // t1) printString, ' bytecodes/sec; ',
      ((r * 1000) // t2) printString, ' sends/sec'
].



-------------------------------------

I get the error:

line 26:9 mismatched input 'r' expecting '|'
line 27:4 mismatched input ':=' expecting ']'
line 27:7 missing EOF at '1'
Exception in thread "main" st.redline.core.RedlineException: Syntax error(s) detected
        at st.redline.core.RedlineException.withMessage(RedlineException.java:19)
        at st.redline.core.Kompiler.parse(Kompiler.java:51)
        at st.redline.core.Kompiler.compileSource(Kompiler.java:30)
        at st.redline.core.Kompiler.compile(Kompiler.java:26)
        at st.redline.core.SmalltalkSourceClassLoader.compile(SmalltalkSourceClassLoader.java:30)
        at st.redline.core.SmalltalkSourceClassLoader.classFrom(SmalltalkSourceClassLoader.java:21)
        at st.redline.core.SmalltalkSourceClassLoader.findClass(SmalltalkSourceClassLoader.java:17)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at st.redline.core.Stic.invoke(Stic.java:79)
        at st.redline.core.Stic.invokeWith(Stic.java:31)
        at st.redline.core.Stic.main(Stic.java:14)




On Sunday, 2 December 2012 20:34:52 UTC-5, jamesl wrote:
To extend an existing class in Redline Smalltalk requires you to send
a message to the class you want to extend to add a new method.

For example:

To add the instance method 'floor' to the Float class we send the
atSelector:put: message to the Float class -

Float atSelector: #floor put: [
   "code that does the floor math."
].

To add the class method 'random' to the Integer class we send the 
atSelector:put: message to the class of the Integer class -

Integer class atSelector: #random put: [
   "code that does the random generation."
].

The code inside the blocks is standard Smalltalk.

Arguments are catered for by adding arguments to the passed in block.
For example:

Integer class atSelector: #randomBetween:and: put: [ :low :hi |
   "code that does the random generation between low and hi."
].

Internally Redline sends these exact same messages when adding the methods
defined in a Class using the -/+.

For example, in class Object:

- yourself
  ^ self.

Becomes:

Object atSelector: #yourself put: [
    ^ self.
].

I hope this helps.

- James.

On Mon, Dec 3, 2012 at 9:36 AM, James Ladd <[hidden email]> wrote:
Of course, this is Smalltalk.

You need to send messages to the Integer class.
I'll post an example in two hours - travelling right now.
- James

Sent from Hyperspace.

On 03/12/2012, at 9:09 AM, Benoit St-Jean <[hidden email]> wrote:

> Is there a way to extend an existing class (say, Integer) without having to modify the core Integer.st file?  I want to add 2-3 methods to the Integer class but I'm wondering if there's a way to do so without modifying the "original" file?






Reply | Threaded
Open this post in threaded view
|

Re: Extending RedLine

James Ladd
+1 

That's the Smalltalk way ;)

Sent from Hyperspace.

On 04/12/2012, at 8:23 AM, Benoit St-Jean <[hidden email]> wrote:

To add my 2 cents, the way I see it is to have most of the stuff done in Smalltalk and use Java for the primitives, the same way all Smalltalk VM have been implemented...

If need be, later, we could provide new primitives/wrappers if we ever need to boost performance in very specific areas...


On Monday, 3 December 2012 16:19:42 UTC-5, jamesl wrote:
A very good question.

Redline is first and foremost a Smalltalk, and secondly handy for talking to Java classes.
Therefore, I would like to see classes provide the functionality of their equivalent in Pharo.
If during their implementation they can wrap or use Java then Redline makes this easy.
To reiterate - First Smalltalk, second Java.

For example, Time should be a port of the Pharo Time class, with only the primitives implemented
in Java. This approach also ensures that as Redline progresses with the implementation of the
Runtime the underlying classes provide those primitives needed by all classes consistently.

Please let me know if this is not clear.

- James.

On Tue, Dec 4, 2012 at 8:08 AM, Steve Wart <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="mKdrpQsGyBsJ">st...@...> wrote:
What's the best practice for implementing these classes? Would you rather see a Smalltalk wrapper around equivalent Java functionality, or new Smalltalk classes built from scratch?

I'd argue for the former, but "equivalency" could prove to be sticky...



On Mon, Dec 3, 2012 at 12:39 PM, James Ladd <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="mKdrpQsGyBsJ">ladd....@...> wrote:
Hi Benoit,

We would more than welcome you implementing the class.

To do this you should fork the Redline Smalltalk github repo,
then ensure that you can build it and run an example class.
You may need to implement a primitive or have a look at one
or two, hence the need to see the source code etc.
Instructions for building the source and testing Redline is
working is found in The Getting Started with Redline Smalltalk
page, Quick Start from the sources section.

You should then follow the implementation of the Time class in
Pharo and port it across to Redline. You may find there are other
classes you will need to port as well depending on the implementation
of Time.

PLEASE write a test around the class. You can see these in the sources.
I'm porting SUinit now but we have a way of testing right now.
Accepting a port is made a LOT easier with supporting tests.

What you are doing is essentially the same thing I will be doing when
the Redline Smalltalk Campaign is over, that is, implementing the full
runtime.

For a primitive you will need to look at the Java methods in PrimObject
that are in the form p<number> - These are primitives. However, to implement
a primitive takes some understanding of the innards of the compiler and
java objects that back the Smalltalk objects, so you might want to call on
us to help you when the time comes.  I'll try and have a quick look today to
see the primitives required.

Good Luck!

- James.


On Mon, Dec 3, 2012 at 11:16 PM, Benoit St-Jean <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="mKdrpQsGyBsJ">benoit...@...> wrote:
Yep, I made another step!  But now, Time>>#millisecondsToRun: isn<t implemented in class Time.  The .st file show that the Time class is empty.  I guess my question now becomes what do I have to do to complete/code it and do you have a list of primitives so I can determine what I have to use to start extending the Time class?


On Sunday, 2 December 2012 22:32:56 UTC-5, jamesl wrote:
I tried the following example which works as expected:

| a b c |
a := 'foo'.
b := 'bar'.
c := a , b.

This results in the following expected Exception:

Exception in thread "main" st.redline.core.RedlineException: Object 'foo' (String) does not understand ',' with arguments:
1    bar

Your example parse fine when a space precedes ',' like this:

^ ((n1 * 500000 * 1000) // t1) printString , ' bytecodes/sec; ' , ((r1 * 1000) // t2) printString , ' sends/sec'.

This will allow you to continue without modification to Redline. I'll raise an issue about requiring the space.

On Mon, Dec 3, 2012 at 1:53 PM, James Ladd <[hidden email]> wrote:
There is an issue with ',' which I am looking into now.

The other issue Redline is giving with 'r' is related to how Redline needs to parse
numbers that can be in '<digits>r' - Renaming the 'r' in your example to r1 gets
you further.

I will look into the ',' issue.


On Mon, Dec 3, 2012 at 1:26 PM, Benoit St-Jean <[hidden email]> wrote:
Here's what I'm trying to add:
-----------------------------------------------------------------

Integer atSelector: #benchFib put: [
^ self < 2
        ifTrue: [1]
        ifFalse: [(self - 1) benchFib + (self - 2) benchFib + 1]
].

Integer atSelector: #benchmark put: [
 | size flags prime k count |
    size := 8190.
    1 to: self do:
        [:iter |
        count := 0.
        flags := (Array new: size) atAllPut: true.
        1 to: size do:
            [:i | (flags at: i) ifTrue:
                [prime := i + 1.
                k := i + prime.
                [k <= size] whileTrue:
                    [flags at: k put: false.
                    k := k + prime].
                count := count + 1]]].
    ^ count
].

Integer atSelector: #tinyBenchmarks put: [
    | t1 t2 r n1 n2 |
    n1 := 1.
    [t1 := Time millisecondsToRun: [n1 benchmark].
    t1 < 1000] whileTrue:[n1 := n1 * 2].

    n2 := 28.
    [t2 := Time millisecondsToRun: [r := n2 benchFib].
    t2 < 1000] whileTrue:[n2 := n2 + 1].
   
    ^ ((n1 * 500000 * 1000) // t1) printString, ' bytecodes/sec; ',
      ((r * 1000) // t2) printString, ' sends/sec'
].



-------------------------------------

I get the error:

line 26:9 mismatched input 'r' expecting '|'
line 27:4 mismatched input ':=' expecting ']'
line 27:7 missing EOF at '1'
Exception in thread "main" st.redline.core.RedlineException: Syntax error(s) detected
        at st.redline.core.RedlineException.withMessage(RedlineException.java:19)
        at st.redline.core.Kompiler.parse(Kompiler.java:51)
        at st.redline.core.Kompiler.compileSource(Kompiler.java:30)
        at st.redline.core.Kompiler.compile(Kompiler.java:26)
        at st.redline.core.SmalltalkSourceClassLoader.compile(SmalltalkSourceClassLoader.java:30)
        at st.redline.core.SmalltalkSourceClassLoader.classFrom(SmalltalkSourceClassLoader.java:21)
        at st.redline.core.SmalltalkSourceClassLoader.findClass(SmalltalkSourceClassLoader.java:17)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at st.redline.core.Stic.invoke(Stic.java:79)
        at st.redline.core.Stic.invokeWith(Stic.java:31)
        at st.redline.core.Stic.main(Stic.java:14)




On Sunday, 2 December 2012 20:34:52 UTC-5, jamesl wrote:
To extend an existing class in Redline Smalltalk requires you to send
a message to the class you want to extend to add a new method.

For example:

To add the instance method 'floor' to the Float class we send the
atSelector:put: message to the Float class -

Float atSelector: #floor put: [
   "code that does the floor math."
].

To add the class method 'random' to the Integer class we send the 
atSelector:put: message to the class of the Integer class -

Integer class atSelector: #random put: [
   "code that does the random generation."
].

The code inside the blocks is standard Smalltalk.

Arguments are catered for by adding arguments to the passed in block.
For example:

Integer class atSelector: #randomBetween:and: put: [ :low :hi |
   "code that does the random generation between low and hi."
].

Internally Redline sends these exact same messages when adding the methods
defined in a Class using the -/+.

For example, in class Object:

- yourself
  ^ self.

Becomes:

Object atSelector: #yourself put: [
    ^ self.
].

I hope this helps.

- James.

On Mon, Dec 3, 2012 at 9:36 AM, James Ladd <[hidden email]> wrote:
Of course, this is Smalltalk.

You need to send messages to the Integer class.
I'll post an example in two hours - travelling right now.
- James

Sent from Hyperspace.

On 03/12/2012, at 9:09 AM, Benoit St-Jean <[hidden email]> wrote:

> Is there a way to extend an existing class (say, Integer) without having to modify the core Integer.st file?  I want to add 2-3 methods to the Integer class but I'm wondering if there's a way to do so without modifying the "original" file?






Reply | Threaded
Open this post in threaded view
|

Re: Extending RedLine

SeanTAllen
In reply to this post by Benoit St-Jean-4
Exactly our think as well.


On Mon, Dec 3, 2012 at 4:23 PM, Benoit St-Jean <[hidden email]> wrote:
To add my 2 cents, the way I see it is to have most of the stuff done in Smalltalk and use Java for the primitives, the same way all Smalltalk VM have been implemented...

If need be, later, we could provide new primitives/wrappers if we ever need to boost performance in very specific areas...



On Monday, 3 December 2012 16:19:42 UTC-5, jamesl wrote:
A very good question.

Redline is first and foremost a Smalltalk, and secondly handy for talking to Java classes.
Therefore, I would like to see classes provide the functionality of their equivalent in Pharo.
If during their implementation they can wrap or use Java then Redline makes this easy.
To reiterate - First Smalltalk, second Java.

For example, Time should be a port of the Pharo Time class, with only the primitives implemented
in Java. This approach also ensures that as Redline progresses with the implementation of the
Runtime the underlying classes provide those primitives needed by all classes consistently.

Please let me know if this is not clear.

- James.

On Tue, Dec 4, 2012 at 8:08 AM, Steve Wart <[hidden email]> wrote:
What's the best practice for implementing these classes? Would you rather see a Smalltalk wrapper around equivalent Java functionality, or new Smalltalk classes built from scratch?

I'd argue for the former, but "equivalency" could prove to be sticky...



On Mon, Dec 3, 2012 at 12:39 PM, James Ladd <[hidden email]> wrote:
Hi Benoit,

We would more than welcome you implementing the class.

To do this you should fork the Redline Smalltalk github repo,
then ensure that you can build it and run an example class.
You may need to implement a primitive or have a look at one
or two, hence the need to see the source code etc.
Instructions for building the source and testing Redline is
working is found in The Getting Started with Redline Smalltalk
page, Quick Start from the sources section.

You should then follow the implementation of the Time class in
Pharo and port it across to Redline. You may find there are other
classes you will need to port as well depending on the implementation
of Time.

PLEASE write a test around the class. You can see these in the sources.
I'm porting SUinit now but we have a way of testing right now.
Accepting a port is made a LOT easier with supporting tests.

What you are doing is essentially the same thing I will be doing when
the Redline Smalltalk Campaign is over, that is, implementing the full
runtime.

For a primitive you will need to look at the Java methods in PrimObject
that are in the form p<number> - These are primitives. However, to implement
a primitive takes some understanding of the innards of the compiler and
java objects that back the Smalltalk objects, so you might want to call on
us to help you when the time comes.  I'll try and have a quick look today to
see the primitives required.

Good Luck!

- James.


On Mon, Dec 3, 2012 at 11:16 PM, Benoit St-Jean <[hidden email]> wrote:
Yep, I made another step!  But now, Time>>#millisecondsToRun: isn<t implemented in class Time.  The .st file show that the Time class is empty.  I guess my question now becomes what do I have to do to complete/code it and do you have a list of primitives so I can determine what I have to use to start extending the Time class?


On Sunday, 2 December 2012 22:32:56 UTC-5, jamesl wrote:
I tried the following example which works as expected:

| a b c |
a := 'foo'.
b := 'bar'.
c := a , b.

This results in the following expected Exception:

Exception in thread "main" st.redline.core.RedlineException: Object 'foo' (String) does not understand ',' with arguments:
1    bar

Your example parse fine when a space precedes ',' like this:

^ ((n1 * 500000 * 1000) // t1) printString , ' bytecodes/sec; ' , ((r1 * 1000) // t2) printString , ' sends/sec'.

This will allow you to continue without modification to Redline. I'll raise an issue about requiring the space.

On Mon, Dec 3, 2012 at 1:53 PM, James Ladd <[hidden email]> wrote:
There is an issue with ',' which I am looking into now.

The other issue Redline is giving with 'r' is related to how Redline needs to parse
numbers that can be in '<digits>r' - Renaming the 'r' in your example to r1 gets
you further.

I will look into the ',' issue.


On Mon, Dec 3, 2012 at 1:26 PM, Benoit St-Jean <[hidden email]> wrote:
Here's what I'm trying to add:
-----------------------------------------------------------------

Integer atSelector: #benchFib put: [
^ self < 2
        ifTrue: [1]
        ifFalse: [(self - 1) benchFib + (self - 2) benchFib + 1]
].

Integer atSelector: #benchmark put: [
 | size flags prime k count |
    size := 8190.
    1 to: self do:
        [:iter |
        count := 0.
        flags := (Array new: size) atAllPut: true.
        1 to: size do:
            [:i | (flags at: i) ifTrue:
                [prime := i + 1.
                k := i + prime.
                [k <= size] whileTrue:
                    [flags at: k put: false.
                    k := k + prime].
                count := count + 1]]].
    ^ count
].

Integer atSelector: #tinyBenchmarks put: [
    | t1 t2 r n1 n2 |
    n1 := 1.
    [t1 := Time millisecondsToRun: [n1 benchmark].
    t1 < 1000] whileTrue:[n1 := n1 * 2].

    n2 := 28.
    [t2 := Time millisecondsToRun: [r := n2 benchFib].
    t2 < 1000] whileTrue:[n2 := n2 + 1].
   
    ^ ((n1 * 500000 * 1000) // t1) printString, ' bytecodes/sec; ',
      ((r * 1000) // t2) printString, ' sends/sec'
].



-------------------------------------

I get the error:

line 26:9 mismatched input 'r' expecting '|'
line 27:4 mismatched input ':=' expecting ']'
line 27:7 missing EOF at '1'
Exception in thread "main" st.redline.core.RedlineException: Syntax error(s) detected
        at st.redline.core.RedlineException.withMessage(RedlineException.java:19)
        at st.redline.core.Kompiler.parse(Kompiler.java:51)
        at st.redline.core.Kompiler.compileSource(Kompiler.java:30)
        at st.redline.core.Kompiler.compile(Kompiler.java:26)
        at st.redline.core.SmalltalkSourceClassLoader.compile(SmalltalkSourceClassLoader.java:30)
        at st.redline.core.SmalltalkSourceClassLoader.classFrom(SmalltalkSourceClassLoader.java:21)
        at st.redline.core.SmalltalkSourceClassLoader.findClass(SmalltalkSourceClassLoader.java:17)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at st.redline.core.Stic.invoke(Stic.java:79)
        at st.redline.core.Stic.invokeWith(Stic.java:31)
        at st.redline.core.Stic.main(Stic.java:14)




On Sunday, 2 December 2012 20:34:52 UTC-5, jamesl wrote:
To extend an existing class in Redline Smalltalk requires you to send
a message to the class you want to extend to add a new method.

For example:

To add the instance method 'floor' to the Float class we send the
atSelector:put: message to the Float class -

Float atSelector: #floor put: [
   "code that does the floor math."
].

To add the class method 'random' to the Integer class we send the 
atSelector:put: message to the class of the Integer class -

Integer class atSelector: #random put: [
   "code that does the random generation."
].

The code inside the blocks is standard Smalltalk.

Arguments are catered for by adding arguments to the passed in block.
For example:

Integer class atSelector: #randomBetween:and: put: [ :low :hi |
   "code that does the random generation between low and hi."
].

Internally Redline sends these exact same messages when adding the methods
defined in a Class using the -/+.

For example, in class Object:

- yourself
  ^ self.

Becomes:

Object atSelector: #yourself put: [
    ^ self.
].

I hope this helps.

- James.

On Mon, Dec 3, 2012 at 9:36 AM, James Ladd <[hidden email]> wrote:
Of course, this is Smalltalk.

You need to send messages to the Integer class.
I'll post an example in two hours - travelling right now.
- James

Sent from Hyperspace.

On 03/12/2012, at 9:09 AM, Benoit St-Jean <[hidden email]> wrote:

> Is there a way to extend an existing class (say, Integer) without having to modify the core Integer.st file?  I want to add 2-3 methods to the Integer class but I'm wondering if there's a way to do so without modifying the "original" file?









--

Sent from my iPhone
Reply | Threaded
Open this post in threaded view
|

Re: Extending RedLine

Les Hazlewood
In reply to this post by James Ladd
+1