Revisión | 2f311f66e33679bdfb1be6dfa06a09a33ccae4bc (tree) |
---|---|
Tiempo | 2010-03-03 19:21:44 |
Autor | Albert Mietus < albert AT ons-huis DOT net > |
Commiter | Albert Mietus < albert AT ons-huis DOT net > |
init
@@ -0,0 +1,70 @@ | ||
1 | + | |
2 | +//-----------Rekenmachine | |
3 | +// /*Keypad*/ // with Keys | |
4 | +// +---------------------+ | |
5 | +// | +-+ +-+ +-+ +-+ | /*Display*/ // a LCD-line | |
6 | +// | |7| |8| |8| |*| | +-----------------------+ | |
7 | +// | +-+ +-+ +-+ +-+ | | | | |
8 | +// | | | <====\\ | |
9 | +// | +-+ +-+ +-+ +-+ | +-----------------------+ || | |
10 | +// | |4| |5| |6| |/| | || | |
11 | +// | +-+ +-+ +-+ +-+ | ||//p:C2D | |
12 | +// | | /*Chip */ || | |
13 | +// | +-+ +-+ +-+ +-+ | /* hidden subcomp */ || | |
14 | +// | |1| |2| |3| |+| | +----------------------------^^--+ | |
15 | +// | +-+ +-+ +-+ +-+ | | | | |
16 | +// | >======> //p: K2C | | |
17 | +// | +-+ +-+ +-+ +-+ | | | | |
18 | +// | |7| |8| |8| |-| | | | | |
19 | +// | +-+ +-+ +-+ +-+ | | | | |
20 | +// | | | | | |
21 | +// | +-+ +-+ +-+ +-+ | | | | |
22 | +// | |.| |0| |<| |=| | +--------------------------------+ | |
23 | +// | +-+ +-+ +-+ +-+ | | |
24 | +// +---------------------+ | |
25 | + | |
26 | + | |
27 | +protocol K2C: Protocol { | |
28 | + kind: event; | |
29 | + pressed(int: key); | |
30 | +} | |
31 | + | |
32 | +protocol C2D: Protocol { | |
33 | + kind: event; | |
34 | + show(string: value); // This --typical numbers-- will be show, erasing the current line | |
35 | +} | |
36 | + | |
37 | + | |
38 | +component Key : Component { | |
39 | + port K2C<out>:outlet; | |
40 | +} | |
41 | + | |
42 | +component Keypad: Component { | |
43 | + port K2C<out>:outlet; | |
44 | +} | |
45 | + | |
46 | +component Chip : Component { | |
47 | + port K2C<in> parseKey; | |
48 | + port C2D<out> show; | |
49 | +} | |
50 | + | |
51 | +component Display: Component { | |
52 | + port K2C<in>:show; | |
53 | +} | |
54 | + | |
55 | +component main : Board { | |
56 | + // main doesn't need any ports; as 'Board' has a build-in Power, that will be connected to all power port of all sub's | |
57 | +} | |
58 | + | |
59 | + | |
60 | +implement main { | |
61 | + // This RekenMachine has 3 subcomponents | |
62 | + sub chip = new Chip; | |
63 | + sub display = new Display; | |
64 | + sub keypad = new Keypad; | |
65 | + | |
66 | + // Make connections | |
67 | + chip.parseKey = keypad.out; // **NOTE: the order does not matter! 'keypad.out = chip.parseKey' has same meaning | |
68 | + display.show = chip.show; // **NOTE: again: the oder is trivial, typical we respect the flow | |
69 | + | |
70 | +} |
@@ -0,0 +1,55 @@ | ||
1 | +;;; Castle-mode.el -- simple major mode to highlight and edit Caste code (see below) | |
2 | +;; (C) ALbert Mietus, 2010. -- Use, copy, change at will | |
3 | +;; http://albert.mietus.nl | |
4 | +;; http://SoftwareBeterMaken.mnl | |
5 | + | |
6 | +;;; *Castle* is an experimental language to introduce/try a _new_ programming concept: | |
7 | +;; _*_Connected Components_*_: A component has ports/connectors to communicate with | |
8 | +;; other components. "Input-ports" are much like functions/methods of classes of | |
9 | +;; OO languages. | |
10 | +;;; The improvement is the "output-port". As a components only describes it own behavoir, | |
11 | +;; it can/may change one of it own output-ports. Depending on the connections, this will | |
12 | +;; result in a change of a input-port, typical of another component. However, the component | |
13 | +;; has no direct controll over other components; unlike classes that directly call lots of | |
14 | +;; methods in lots of other classes. | |
15 | +;; Note 1: like in functions, and classes, components can be build out of other components. | |
16 | +;; This is done by instantating (like in OO) components and connecting them. So, a component | |
17 | +;; has direct controll over inputs of "subcomponents". | |
18 | +;; Note 2: Changing a input-port typical triggers a component. However, a component does/can have | |
19 | +;; own behavoir. | |
20 | + | |
21 | +;;; Caste-mode is experimental, and build around generic-mode. It's main use is to be able to | |
22 | +;; write Caste-code in emacs to find the best syntax. There is no compiler yet! | |
23 | + | |
24 | +(require 'generic-x) | |
25 | + | |
26 | +(defconst Caste-CC-kinds '("event" "stream" "power" "in" "out" "bidirect") | |
27 | + "list of all Caste kind keywords") | |
28 | + | |
29 | +(defconst Caste-CC-keywords '("component" "protocol" "implement" "port" "sub" "kind") | |
30 | + "list of all Caste's 'Connected Components' keywords") | |
31 | + | |
32 | +(defconst Caste-CC-Bases '("Component" "Protocol" "Power" "Board") | |
33 | + "list of all basic CC-components") | |
34 | + | |
35 | +(defconst Caste-normal-keywords | |
36 | + '("int" "float" "char" "string" ; basic C-like types -- string is more complex | |
37 | + "for" "return") ; basic C-line flow-keywords | |
38 | + "keywords of Caste, that are normal, as in othert languages like C") | |
39 | + | |
40 | +(defun Caste-mk-fontlock-re (wordlist) | |
41 | + (concat "\\([^A-Za-z0-9_]\\|^\\)\\(" | |
42 | + (mapconcat (lambda (w) w ) wordlist "\\|") | |
43 | + "\\)\\b")) | |
44 | + | |
45 | +(define-generic-mode 'Castle-mode | |
46 | + '("//" ("/*" . "*/")) ;comment | |
47 | + (append Caste-CC-keywords Caste-normal-keywords) | |
48 | + (list ; more highlighting | |
49 | + (list (Caste-mk-fontlock-re Caste-CC-kinds) 2 font-lock-type-face) | |
50 | + (list (Caste-mk-fontlock-re Caste-CC-Bases) 2 font-lock-preprocessor-face) | |
51 | + '("\\([A-Za-z0-9_]+\\)([^)]*)" 1 font-lock-function-name-face) | |
52 | + (list (concat "\\(" (Caste-mk-fontlock-re Caste-CC-keywords) "\\)" " +" "\\(" "[A-Za-z0-9_]+" "\\)") 4 font-lock-type-face) | |
53 | + ) | |
54 | + '(".Castle\\'") ;ext to trigger this mode | |
55 | + nil) ; list of setup-functions |