summaryrefslogtreecommitdiff
path: root/howlers/src/howler.jac
blob: 5789e20c7f4938921ad4e3961f04451d62ac2be7 (plain)
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
73
import sys;
import mmap;
import struct;
import from typing { List, Dict }
import from os { path }

glob MAX_EVENTS:    int = 256;
glob DIR_SCRIPTS:   str = "";

enum EVENT {
    CHLD_PROC_START,
	CHLD_PROC_DONE,
	CHLD_PROC_FAILED,
	CHLD_PROC_HURT,
	CHLD_PROC_HEALING,
	CHLD_PROC_HEALED
}

glob EventName: Dict[EVENT, str] = {
    CHLD_PROC_START:    "child_start",
    CHLD_PROC_DONE:     "child_done",
    CHLD_PROC_FAILED:   "child_failed",
    CHLD_PROC_HURT:     "child_hurt",
    CHLD_PROC_HEALING:  "child_healing",
    CHLD_PROC_HEALED:   "child_healed"
};

obj SysLurchEvent_t {
    has eventTime:  int;
    has eventKind:  EVENT;
    has eventID:    int;
    has data1:      int;
    has data2:      int;
}

obj WatchMen {
    static has eventHead:   int;
    static has eventTail:   int;
    static has EventQue:    List[bytes(SysLurchEvent_t)];

    static def isBufferFull() -> bool {
        report ((eventHead + 1) % MAX_EVENTS) == eventTail;
    }
}

node Website {
    has url:            str;
    has timemout:       int;
    has retry:          int;
    has script:         str;

    has:priv _globals:  Dict;
    has:priv _locals:   Dict;

    can run with Crawler entry {
        exec(script, _globals, _locals);
        # do stuff with the data
    }
}

walker Crawler {
    has data: Dict[str, ...];

    can crawl with Website entry {
        self.data[visit.url] = visit.data;
    }
}

def fix_scrape_script(script: str) -> str by llm();

with entry {
    print("Hello, World!");
}