forked from skx/go.vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.in
87 lines (70 loc) · 1.5 KB
/
types.in
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
#
# About
#
# This program tests our type-handling - which is basic.
#
# Usage:
#
# $ go.vm run ./types.in
#
# Or compile, then execute:
#
# $ go.vm compile ./types.in
# $ go.vm execute ./types.raw
#
store #1, 43
is_integer #1
jmpz ok1
store #1, "ERR - Failed int-test\n"
print_str #1
exit
:ok1
store #1, "OK - Int-test succeeded\n"
print_str #1
store #1, "Steve"
is_string #1
jmpz ok2
store #1, "ERR - Failed string-test\n"
print_str #1
exit
:ok2
store #1, "OK - string-test succeeded\n"
print_str #1
#
# Now we'll try converting a string to an integer
#
store #1, "32"
string2int #1
is_integer #1
jmpz ok3
# failed to convert
store #1, "Failed to convert string to integer\n"
print_str #1
exit
:ok3
store #1, "Converted string to int!\n"
print_str #1
#
# Now we'll try converting an integer to a string
#
store #1, 32
int2string #1
is_string #1
jmpz ok4
# failed to convert
store #1, "Failed to convert integer to string\n"
print_str #1
exit
:ok4
store #1, "Converted int to string!\n"
print_str #1
#
# Since we know we have a string the is_integer should faile
#
is_integer #1
jmpz fail2
exit
:fail2
store #1, "We failed though"
print_str #1
exit