aboutsummaryrefslogtreecommitdiff
path: root/softwords/forml.fr
blob: cc684e08613173f753f983b3113a6512c0b879b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
\ examples from FORML conference paper Nov 98
\ sadler
.( loading FORML examples ) cr
object --> sub c-example
             cell: .cell0
    c-4byte   obj: .nCells
  4 c-4byte array: .quad
       c-byte obj: .length
         79 chars: .name

    : init   ( inst class -- )
        2dup  object => init
        s" aardvark"  2swap  --> set-name
    ;

    : get-name  ( inst class -- c-addr u )
        2dup 
        --> .name  -rot      ( c-addr inst class )
        --> .length --> get
    ;

    : set-name  { c-addr u 2:this -- }
        u       this --> .length --> set
        c-addr  this --> .name  u move
    ;

    : ?  ( inst class ) c-example => get-name type cr ;
end-class


: test ." this is a test" cr ;
' test
c-word --> ref testref

\ add a method to c-word...
c-word --> get-wid ficl-set-current
\ list dictionary thread
: list  ( inst class )
    begin
        2dup --> get-name type cr 
        --> next over 
    0= until
    2drop
;
set-current 

object subclass c-led
    c-byte obj: .state

    : on   { led# 2:this -- }
        this --> .state --> get
        1 led# lshift or dup !oreg
        this --> .state --> set
    ;

    : off   { led# 2:this -- }
        this --> .state --> get
        1 led# lshift invert and dup !oreg
        this --> .state --> set
    ;

end-class


object subclass c-switch

    : ?on   { bit# 2:this -- flag }
        
        1 bit# lshift
    ;
end-class