summaryrefslogtreecommitdiff
path: root/small-tests/examp.tnsl
blob: 196db40eab7ff56fbad6a826a5868df6b5b9305c (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#Comment like this

/#
  Or like this (blocks begin with /<symbol> and end with <symbol>/)
  Block Comment
#/
/##
  Doc Comment
#/

# Preprocessor directives are like this
# Import an external module from library using '
:import 'what'
# Import from local file using "
:import "what/what.tnsl"

# Code lines start with ;

# pass a variable
;int s = 3

;byte bitbyte = .2


# generic scope block

# d does not exist

/; # Scope
  
  ;int d = 1
  # d exists
  ;s = d

;/ # Scope end

# d does not exist


# Function def:
# Any non-reserved word
# Sig: [output1, output2] (input1, input2)
# Main may have 
/;main ({}string str) [int] # Doesn't matter what order the sig is in
  # Main may also omit either for void sig


  # {} represents a tnsl style array
  # ~ before var represents address var
  # ~ after a address var represents the data the address points at
  
  ;int i = 1
  ;~int j ~= i # address of int j = address of i
  j~ = 2 # i = 2 # data of j = 2

  # /;loop represents the only loop in tnsl
  # loop is followed by (init statements) [multi statements]
  # where the first statement in multi is the test, and the once statements are only run once at the beginning of the loop
  /;loop [i!==1]
    # Do something
    ; i = 1
  ;/

;/ # End main



# The struct keyword is followed by <name> {values}
;struct s1 {string Name, string Message = "Default message (c-style strings)"}

# Most people should declare as such:
;struct s1 {
    string Name,
    string Message = "Default message (c-style strings)"
}

# When defining a new struct, use {}
;s1 a = {}
# Same as
;s1 a{}
;a.Name = "Kyle Gunger"

;~s1 b = ~a
;b~.Name # "Kyle Gunger"

# Quick initialization
;s1 c = {"", ""}
# These come in the same order that they do in the struct, so {Name, Message} in this case.

# You can also specify
;s1 d{
    Message = "Message",
    Name = "Name"
}




# This is how arrays are defined as well.
;{}int a = {
  1, 2, 3, 4
}

# Same as
;{}int a{
  1, 2, 3, 4
}


# You may also define an initializer like such:
/;s1 [s1]
  # Initializer must be named same as struct, and must return one of the structs as its only output
  return new s1{"Kyle", "TNSL Creator"}
;/

/; if (i == 3)

# Quick define new block
;;else

;/

/; switch (i)
  # You can do stuff here as well
  ;int t = 0

  # Case block
  /;case 1
    ;i = 0
    ;t = 2
    ;break

  ;;case 2
    ;i = 1
    ;t = 2
    ;break

  ;;default
    ;i = 3
    ;break
  ;/

  # You can do stuff here too
  /; if [t == 2]
    ;i = t - i

  ;;else if [t==3]
    ;i = t+i
  ;/

  # Second case block
  /;case 1
    ;i = 4
  ;/
;/


# Dumb generic type struct
; struct gen (type T) {
  T i
}

# This seems dumb
;gen(int) j{2}

# But this seems dumber
;{}gen(gen(int)) j{
  {{1}},
  {{2}},
  {{3}}
}