2017-01-09 12:52:37 +00:00
|
|
|
#include 'Moo.moo'.
|
|
|
|
|
|
|
|
class Mill(Object)
|
|
|
|
{
|
2017-04-19 16:46:44 +00:00
|
|
|
var registrar.
|
|
|
|
var obj.
|
2017-01-09 12:52:37 +00:00
|
|
|
|
|
|
|
method initialize
|
|
|
|
{
|
|
|
|
self.registrar := Dictionary new.
|
|
|
|
}
|
|
|
|
|
|
|
|
method register: name call: callable
|
|
|
|
{
|
|
|
|
| k |
|
|
|
|
(k := self.registrar at: name) isNil ifTrue: [
|
|
|
|
self.registrar at: name put: [
|
|
|
|
self.obj isNil ifTrue: [
|
|
|
|
self.obj := callable value.
|
|
|
|
].
|
|
|
|
self.obj
|
|
|
|
].
|
|
|
|
].
|
|
|
|
|
|
|
|
^k
|
|
|
|
}
|
|
|
|
|
|
|
|
method make: name
|
|
|
|
{
|
|
|
|
| k |
|
|
|
|
|
|
|
|
(k := self.registrar at: name) notNil ifTrue: [
|
|
|
|
^k value.
|
|
|
|
].
|
|
|
|
|
|
|
|
^nil.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyObject(Object)
|
|
|
|
{
|
2017-01-18 17:17:05 +00:00
|
|
|
method(#class) mainxx
|
2017-01-09 12:52:37 +00:00
|
|
|
{
|
2017-01-10 10:50:26 +00:00
|
|
|
| d a ffi |
|
2017-01-09 12:52:37 +00:00
|
|
|
|
2019-06-19 12:38:09 +00:00
|
|
|
/*k := Mill new.
|
2017-01-09 12:52:37 +00:00
|
|
|
k register: #abc call: [ Dictionary new ].
|
|
|
|
a := k make: #abc.
|
2019-06-27 06:29:09 +00:00
|
|
|
//a dump.*/
|
2017-01-09 12:52:37 +00:00
|
|
|
|
|
|
|
d := Dictionary new.
|
|
|
|
d at: #abc put: 20.
|
|
|
|
d at: #dddd put: 40.
|
|
|
|
d at: #jjjj put: 'hello world'.
|
|
|
|
d at: #moo put: 'good?'.
|
|
|
|
d at: #moo put: 'not good?'.
|
|
|
|
|
2019-06-19 12:38:09 +00:00
|
|
|
/* (d at: #abc) dump.
|
|
|
|
/* (d at: #dddd) dump. */
|
|
|
|
/*d do: [:v | v dump].*/
|
2017-01-09 12:52:37 +00:00
|
|
|
|
|
|
|
d keysAndValuesDo: [:k :v| System logNl: (k asString) & ' => ' & (v asString) ].
|
|
|
|
|
2019-06-27 06:29:09 +00:00
|
|
|
//(d includesAssociation: (Association key: #moo value: 'not good?')) dump.
|
2017-01-09 12:52:37 +00:00
|
|
|
'-------------------------' dump.
|
2019-06-27 06:29:09 +00:00
|
|
|
//(System at: #MyObject) dump.
|
2017-01-09 12:52:37 +00:00
|
|
|
(d removeKey: #moo) dump.
|
|
|
|
d removeKey: #abc ifAbsent: [System logNl: '#moo not found'].
|
|
|
|
d keysAndValuesDo: [:k :v| System logNl: (k asString) & ' => ' & (v asString) ].
|
|
|
|
|
|
|
|
'-------------------------' dump.
|
|
|
|
(d at: #jjjj) dump.
|
|
|
|
(d at: #jjjja) dump.
|
|
|
|
|
2019-06-19 12:38:09 +00:00
|
|
|
/*
|
2017-01-09 12:52:37 +00:00
|
|
|
System keysAndValuesDo: [:k :v|
|
|
|
|
System logNl: (k asString) & ' => ' & (v asString)
|
|
|
|
].
|
2019-06-19 12:38:09 +00:00
|
|
|
*/
|
2017-01-09 12:52:37 +00:00
|
|
|
|
2019-06-27 06:29:09 +00:00
|
|
|
//System keysDo: [:k| System logNl: (k asString)]
|
2017-01-09 12:52:37 +00:00
|
|
|
|
2019-06-19 12:38:09 +00:00
|
|
|
/*[
|
2017-01-09 12:52:37 +00:00
|
|
|
[Exception hash dump] ensure: ['xxxx' dump].
|
2019-06-19 12:38:09 +00:00
|
|
|
] on: Exception do: [:ex | ('Exception caught - ' & ex asString) dump ].*/
|
2017-01-10 10:50:26 +00:00
|
|
|
|
|
|
|
ffi := FFI new: '/lib64/libc.so.6'.
|
2017-01-18 17:17:05 +00:00
|
|
|
if (ffi isError)
|
|
|
|
{
|
|
|
|
System logNl: 'cannot open libc.so'
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
(ffi call: #getpid signature: ')i' arguments: nil) dump.
|
|
|
|
(ffi call: #printf signature: 's|iis)i' arguments: #(S'A=>%d B=>%d Hello, world %s\n' 1 2 'fly away')) dump.
|
|
|
|
(ffi call: #printf signature: 's|iis)i' arguments: #(S'A=>%d B=>%d Hello, world %s\n' 1 2 'jump down')) dump.
|
|
|
|
ffi close.
|
2018-06-19 16:58:04 +00:00
|
|
|
}.
|
2018-11-06 06:26:34 +00:00
|
|
|
|
2017-01-18 17:17:05 +00:00
|
|
|
(('abcd' == 'abcd') ifTrue: [1] ifFalse: [2]) dump.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-06 17:53:33 +00:00
|
|
|
|
|
|
|
method(#class) main_xx
|
2017-01-18 17:17:05 +00:00
|
|
|
{
|
|
|
|
|a k|
|
2017-03-31 14:21:22 +00:00
|
|
|
|
2017-01-22 18:01:26 +00:00
|
|
|
'BEGINNING OF main...........' dump.
|
2017-01-18 17:17:05 +00:00
|
|
|
a :=
|
|
|
|
if ([System logNl: 'xxxx'. 'abcd' == 'bcde'. false] value)
|
|
|
|
{
|
|
|
|
System logNl: 'XXXXXXXXX'.
|
|
|
|
1111
|
|
|
|
}
|
|
|
|
elsif ('abcd' ~= 'abcd')
|
|
|
|
{
|
|
|
|
System logNl: 'second if'.
|
|
|
|
}
|
|
|
|
elsif ([k := 20. System logNl: 'k => ' & (k asString). k + 20. true] value)
|
|
|
|
{
|
|
|
|
System logNl: 'THIRID forever.............' & (k asString)
|
|
|
|
}
|
|
|
|
elsif (true = true)
|
|
|
|
{
|
|
|
|
System logNl: 'forever.............'
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
System logNl: 'NO MATCH'.
|
|
|
|
[true] value.
|
|
|
|
}.
|
|
|
|
|
|
|
|
a dump.
|
2017-01-19 17:12:16 +00:00
|
|
|
|
|
|
|
(if (false) { 10 } else { 16rFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}) dump.
|
|
|
|
|
2017-01-18 17:17:05 +00:00
|
|
|
System logNl: 'DONE DONE DONE...'.
|
2017-01-19 17:12:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
(if (false) {} else {1.} ) dump.
|
2017-01-22 18:01:26 +00:00
|
|
|
|
|
|
|
'TESTING ^^....' dump.
|
|
|
|
a := 10.
|
|
|
|
([
|
|
|
|
a := a + 3.
|
|
|
|
if (a > 10) {^^99 }
|
|
|
|
] value) dump.
|
|
|
|
|
|
|
|
a := 5.
|
2019-06-27 06:29:09 +00:00
|
|
|
//((a < 20) ifTrue: [ 1. if (a < 20) { ^^50 }. 90. ]) dump.
|
2017-01-22 18:01:26 +00:00
|
|
|
([true] whileTrue: [
|
2017-01-25 13:57:14 +00:00
|
|
|
[true] whileTrue: [
|
|
|
|
[
|
|
|
|
'aaa' dump.
|
|
|
|
if (a > 20) { ^^506070 }.
|
|
|
|
a := a + 1.
|
|
|
|
'bbb' dump.
|
|
|
|
] ensure: [('xxxxx' & a asString) dump].
|
|
|
|
]
|
2017-01-22 18:01:26 +00:00
|
|
|
]) dump.
|
2017-01-25 13:57:14 +00:00
|
|
|
|
2019-06-19 12:38:09 +00:00
|
|
|
/*
|
2017-01-25 13:57:14 +00:00
|
|
|
a := 5.
|
|
|
|
while (true) {
|
|
|
|
System logNl: a asString.
|
|
|
|
a := a + 100000000000000.
|
2019-06-19 12:38:09 +00:00
|
|
|
}.*/
|
2017-01-22 18:01:26 +00:00
|
|
|
|
2017-01-31 16:14:11 +00:00
|
|
|
|
|
|
|
a := if(false) { 10 } elsif (false) { 20 } elsif (false) { 30} else { 40}.
|
2019-06-27 06:29:09 +00:00
|
|
|
//a := if(false) { 999 } else { 888 }.
|
2017-01-31 16:14:11 +00:00
|
|
|
a dump.
|
|
|
|
|
2017-01-27 15:25:46 +00:00
|
|
|
a := 5.
|
2017-01-30 16:48:42 +00:00
|
|
|
a := while (true)
|
2017-01-27 15:25:46 +00:00
|
|
|
{
|
|
|
|
a := a + 1.
|
2019-06-27 06:29:09 +00:00
|
|
|
//if (a > 20) { break if (true) { break. }. }.
|
2017-01-30 16:48:42 +00:00
|
|
|
if (a > 20) {
|
2019-06-27 06:29:09 +00:00
|
|
|
^if (true) { break } else {10}. // return gets ignored for break.
|
2017-01-30 16:48:42 +00:00
|
|
|
}.
|
2017-01-29 07:14:36 +00:00
|
|
|
a dump.
|
2017-01-27 15:25:46 +00:00
|
|
|
}.
|
2017-01-31 16:14:11 +00:00
|
|
|
a dump.
|
2017-02-05 13:54:52 +00:00
|
|
|
|
2017-01-30 16:48:42 +00:00
|
|
|
a := 5.
|
2017-02-05 13:54:52 +00:00
|
|
|
do {
|
|
|
|
a := do {
|
|
|
|
('in loop.....' & a asString) dump.
|
2019-06-27 06:29:09 +00:00
|
|
|
//if (a > 5) { break }.
|
2017-02-05 13:54:52 +00:00
|
|
|
a := a + 1.
|
|
|
|
} while(a < 10).
|
|
|
|
} while (false).
|
2017-01-30 16:48:42 +00:00
|
|
|
a dump.
|
2017-01-29 07:29:58 +00:00
|
|
|
|
2019-06-27 06:29:09 +00:00
|
|
|
// these should be elimited by the compiler.
|
2017-01-29 07:29:58 +00:00
|
|
|
nil.
|
|
|
|
1.
|
|
|
|
0.
|
|
|
|
self.
|
|
|
|
thisProcess.
|
|
|
|
thisContext.
|
|
|
|
nil.
|
|
|
|
nil.
|
2019-06-27 06:29:09 +00:00
|
|
|
// end of elimination.
|
2017-02-02 04:46:29 +00:00
|
|
|
|
2019-06-27 06:29:09 +00:00
|
|
|
// PROBLEM: the following double loop will exhaust the stack
|
2017-02-06 17:53:33 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
2019-06-27 06:29:09 +00:00
|
|
|
//[:j :q | (j + q) dump] value: (if (true) { 20 }) value: (if (true) { break }).
|
2017-02-06 17:53:33 +00:00
|
|
|
(1 + (if (false) {} else { break })) dump.
|
|
|
|
}.
|
|
|
|
}.
|
|
|
|
|
|
|
|
|
2017-02-05 13:54:52 +00:00
|
|
|
a :=999.
|
2017-06-16 09:45:22 +00:00
|
|
|
a := %(
|
2017-02-05 13:54:52 +00:00
|
|
|
1,
|
|
|
|
2,
|
|
|
|
a,
|
|
|
|
4,
|
|
|
|
1 + 1,
|
2017-06-16 09:45:22 +00:00
|
|
|
%( 1, 2, %(a, a := a + 1, a, if (a > 10) { a + 20 } ), 3),
|
2017-02-05 15:05:25 +00:00
|
|
|
2 + 2,
|
|
|
|
#'a b c'
|
2017-06-16 09:45:22 +00:00
|
|
|
).
|
2017-02-05 15:05:25 +00:00
|
|
|
|
2019-06-19 12:38:09 +00:00
|
|
|
/* Dictionary ???
|
2017-06-16 09:45:22 +00:00
|
|
|
a := %{
|
2017-03-09 07:26:43 +00:00
|
|
|
key -> value ,
|
|
|
|
key -> value ,
|
|
|
|
key -> value ,
|
|
|
|
key -> value
|
2017-06-16 09:45:22 +00:00
|
|
|
),.
|
2019-06-19 12:38:09 +00:00
|
|
|
*/
|
2017-02-06 17:53:33 +00:00
|
|
|
|
2017-02-05 13:54:52 +00:00
|
|
|
a do: [ :v | v dump].
|
|
|
|
|
2019-06-19 12:38:09 +00:00
|
|
|
/*
|
2019-06-27 06:29:09 +00:00
|
|
|
// how to handle return inside 'if' like the following???
|
|
|
|
// what happens to the stack?
|
2017-02-05 13:54:52 +00:00
|
|
|
a := if ((k := 20) == 10) {99} else { 100}.
|
|
|
|
k dump.
|
|
|
|
a dump.
|
2019-06-19 12:38:09 +00:00
|
|
|
*/
|
2017-01-22 18:01:26 +00:00
|
|
|
'---------- END ------------' dump.
|
2019-06-27 06:29:09 +00:00
|
|
|
//System sleepForSecs: 20.
|
2017-01-09 12:52:37 +00:00
|
|
|
}
|
2017-02-06 17:53:33 +00:00
|
|
|
|
2017-02-07 17:40:34 +00:00
|
|
|
|
|
|
|
|
2017-02-06 17:53:33 +00:00
|
|
|
method(#class) main
|
|
|
|
{
|
2017-03-23 16:14:22 +00:00
|
|
|
|a i|
|
2017-03-24 18:09:34 +00:00
|
|
|
|
2019-06-27 06:29:09 +00:00
|
|
|
//#self main_xx.
|
2017-03-31 14:21:22 +00:00
|
|
|
|
2017-02-07 17:40:34 +00:00
|
|
|
a := 100.
|
2019-06-27 06:29:09 +00:00
|
|
|
// PROBLEM: the following double loop will exhaust the stack
|
2019-06-19 12:38:09 +00:00
|
|
|
/*
|
2017-02-06 17:53:33 +00:00
|
|
|
while (true)
|
|
|
|
{
|
2019-06-27 06:29:09 +00:00
|
|
|
//111 dump.
|
2017-02-06 17:53:33 +00:00
|
|
|
while (true)
|
|
|
|
{
|
2019-06-27 06:29:09 +00:00
|
|
|
//[:j :q | (j + q) dump] value: (if (true) { 20 }) value: (if (true) { break }).
|
2017-02-06 17:53:33 +00:00
|
|
|
(1 + (if (false) {} else { break })) dump.
|
2019-06-27 06:29:09 +00:00
|
|
|
//break.
|
|
|
|
//[:j :q | (j + q) dump] value: 10 value: 20.
|
|
|
|
//if (false) {} else { break }.
|
2017-02-06 17:53:33 +00:00
|
|
|
}.
|
2019-06-19 12:38:09 +00:00
|
|
|
}.*/
|
2017-03-09 07:26:43 +00:00
|
|
|
|
2017-02-07 17:40:34 +00:00
|
|
|
|
2017-06-16 09:45:22 +00:00
|
|
|
a := %{
|
2017-03-09 07:26:43 +00:00
|
|
|
'aaa' -> 10,
|
|
|
|
'bbb' -> 20,
|
|
|
|
'bbb' -> 30,
|
|
|
|
#bbb -> 40,
|
|
|
|
Association key: 12343 value: 129908123,
|
2019-06-27 06:29:09 +00:00
|
|
|
//5 -> 99,
|
2017-03-09 07:26:43 +00:00
|
|
|
'ccc' -> 890
|
2017-02-06 17:53:33 +00:00
|
|
|
}.
|
2017-02-10 07:38:29 +00:00
|
|
|
|
2019-06-19 12:38:09 +00:00
|
|
|
/*a removeKey: 'bbb'.
|
|
|
|
a remove: :(#bbb).*/
|
2017-02-10 07:38:29 +00:00
|
|
|
|
2019-06-27 06:29:09 +00:00
|
|
|
//1 to: 100 do: [ :i | a at: i put: (i * 2) ].
|
2017-02-07 17:40:34 +00:00
|
|
|
a keysAndValuesDo: [:k :v |
|
|
|
|
k dump.
|
|
|
|
v dump.
|
|
|
|
'------------' dump.
|
|
|
|
].
|
|
|
|
|
2017-03-09 07:26:43 +00:00
|
|
|
(a associationAt: (#aaa -> nil)) dump.
|
2019-06-19 12:38:09 +00:00
|
|
|
/*
|
2017-02-09 10:22:44 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
[:j :q | (j + q) dump] value: (if (true) { 20 }) value: (if (true) { break }).
|
|
|
|
(1 + (if (false) {} else { break })) dump.
|
|
|
|
}
|
2019-06-19 12:38:09 +00:00
|
|
|
}*/
|
2017-03-09 07:26:43 +00:00
|
|
|
|
2017-03-22 16:55:41 +00:00
|
|
|
|
2017-03-23 16:14:22 +00:00
|
|
|
|
|
|
|
|
2019-06-19 12:38:09 +00:00
|
|
|
/* basicAt: 12 to access the nsdic field. use a proper method once it's defined in Class */
|
2019-06-27 06:29:09 +00:00
|
|
|
// (System nsdic) keysAndValuesDo: [:k :v |
|
|
|
|
// k dump.
|
|
|
|
// v dump.
|
|
|
|
// '------------' dump.
|
|
|
|
// ].
|
2017-03-22 16:55:41 +00:00
|
|
|
|
2017-03-23 16:14:22 +00:00
|
|
|
|
|
|
|
(System at: #Processor) dump.
|
|
|
|
System logNl: 'Sleeping start now....'.
|
2017-03-30 14:59:55 +00:00
|
|
|
|
2017-04-03 13:24:18 +00:00
|
|
|
|
2017-12-08 15:28:51 +00:00
|
|
|
a := System malloc(200).
|
2017-04-03 13:24:18 +00:00
|
|
|
i := 0.
|
|
|
|
while (i < 26)
|
|
|
|
{
|
2017-04-28 04:03:52 +00:00
|
|
|
a putUint8(i, ($A asInteger + i)).
|
2018-06-19 16:58:04 +00:00
|
|
|
System putUint8(a, i, ($A asInteger + i)).
|
2017-04-03 13:24:18 +00:00
|
|
|
i := i + 1.
|
|
|
|
}.
|
|
|
|
while (i > 0)
|
|
|
|
{
|
|
|
|
i := i - 1.
|
|
|
|
a getUint8(i) asCharacter dump.
|
|
|
|
}.
|
|
|
|
a getUint32(0) dump.
|
2017-04-28 04:03:52 +00:00
|
|
|
a getUint32(1) dump.
|
2017-04-03 13:24:18 +00:00
|
|
|
|
2019-06-27 06:29:09 +00:00
|
|
|
//a dump.
|
|
|
|
//System free(a).
|
2017-04-03 05:43:50 +00:00
|
|
|
a free.
|
2017-04-03 13:24:18 +00:00
|
|
|
|
2017-11-05 16:47:13 +00:00
|
|
|
System sleepForSecs: 2.
|
2017-02-06 17:53:33 +00:00
|
|
|
}
|
2017-02-11 05:48:30 +00:00
|
|
|
|
2019-06-19 12:38:09 +00:00
|
|
|
/*
|
2017-02-11 05:48:30 +00:00
|
|
|
#method(#class) main
|
|
|
|
{
|
|
|
|
| event |
|
|
|
|
|
|
|
|
Timer fire: [ 'Timer job' dump. ] in: 3000.
|
|
|
|
|
|
|
|
GUI on: #XXX do: [:evt | ... ].
|
|
|
|
GUI on: #YYYY do: [:evt | ... ].
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
event := GUI waitForEvent.
|
|
|
|
GUI dispatchEvent: event.
|
|
|
|
}
|
2019-06-19 12:38:09 +00:00
|
|
|
}*/
|
2017-01-16 14:42:39 +00:00
|
|
|
}
|
2017-02-07 17:40:34 +00:00
|
|
|
|
2019-06-19 12:38:09 +00:00
|
|
|
/*
|
2017-02-07 17:40:34 +00:00
|
|
|
pooldic XXD {
|
|
|
|
#abc := #(1 2 3).
|
2019-06-27 06:29:09 +00:00
|
|
|
#def := %( 1, 3, 4 ). // syntax error - literal expected where %( is
|
2017-02-07 17:40:34 +00:00
|
|
|
}
|
2019-06-19 12:38:09 +00:00
|
|
|
*/
|