summaryrefslogtreecommitdiff
path: root/tnslc/tnslc_wrapped.tnsl
blob: 77d7c13df93544f7ce1480248d61e650ceb4dae3 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
:include "c_wrap.tnsl"
:include "vector.tnsl"
:include "utils.tnsl"

enum TOKEN_TYPE [int] {
    DEFWORD = 0
}

struct Token {
    int line, ch, _type,
    ~uint8 data
}

/; method Token
    /; init
        self.data = _alloc(1)
        self.data{0} = 0
    ;/

    /; data_len [int]
        return cstr_len(self.data)
    ;/

    /; append (uint8 ch)
        int l = self.data_len()
        self.data = _realloc(self.data, self.data_len() + 1)
        self.data{l + 1} = 0
        self.data{l} = ch
    ;/

    /; pop
        int l = self.data_len()
        self.data = _realloc(self.data, l - 1)
        self.data{l - 1} = 0
    ;/

    /; clear
        _delete(self.data)
    ;/

    /; eq (~Token t) [bool]
        return cstr_eq(self.data, t`.data)
    ;/
;/

/; tokenize (~void file) [Vector]
    Vector out
    out.start(32)



    return out
;/

{}uint8 wrong_args = "Usage: copy [from] [to]"
{}uint8 write_one = "\0\n\0"

# Proof of concept copy program
/; main (int argc, ~~uint8 argv) [int]
    asm "mov r8, rcx"
    asm "mov r9, rdx"

    /; if (argc < 3)
        _printf(~wrong_args{0})
        return 1
    ;/

    ~void read_handle = _open_file(argv{1})
    ~void write_handle = _create_file(argv{2})

    _print_num(~_dec{0}, read_handle)
    _print_num(~_dec{0}, write_handle)

    uint8 buf = 0
    int read_count = 0
    int tries = 0
    _read_byte(read_handle, ~buf, ~read_count)
    /; loop (_read_byte(read_handle, ~buf, ~read_count))
        /; if (read_count == 0)
            break
        ;/
        _write_byte(write_handle, ~buf)
        read_count = 0
    ;/

    _close_file(read_handle)
    _close_file(write_handle)

    return 0
;/