annotate samples/stringops.tp @ 251:2557ce4e671f

Fix a couple of compiler bugs. topenv was getting initialized in multiple places. This resulted in multiple copies of modules getting created which caused problems for macro expansion. Additionally, arguments were not being marked as declared during code generation so assigning to an argument that was not closed over generated invalid C code.
author Michael Pavone <pavone@retrodev.com>
date Fri, 11 Apr 2014 22:29:32 -0700
parents 38140b7dbe3d
children 32964a4e7a33
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43
27a2167663dd Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #{
27a2167663dd Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2 main <- {
27a2167663dd Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3 print: "foo: " . 42 . "\n"
27a2167663dd Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4 print: (string: (length: "foo" . "bar")) . "\n"
150
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
5 print: (string: ("foobarbaz" find: "foo" else: { "not found" })) . "\n"
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
6 print: (string: ("foobarbaz" find: "bar" else: { "not found" })) . "\n"
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
7 print: (string: ("foobarbaz" find: "baz" else: { "not found" })) . "\n"
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
8 print: (string: ("foobarbaz" find: "qux" else: { "not found" })) . "\n"
151
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
9
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
10 print: ("foobarbaz" from: 3) . "\n"
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
11 print: ("foobarbaz" from: 3 withLength: 3) . "\n"
152
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
12
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
13 foreach: ("foo,bar,baz,qux" splitOn: ",") :idx val {
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
14 print: val . "\n"
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
15 }
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
16
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
17 res <- "foobarbaz" partitionOn: "bar"
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
18 print: "Before: " . (res before) . "\n"
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
19 print: "After: " . (res after) . "\n"
158
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
20
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
21 print: (string: ("12abcDEF" parseHex32)) . "\n"
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
22 print: (string: ("FFFFFFFFFF" parseHex64)) . "\n"
43
27a2167663dd Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
23 }
27a2167663dd Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24 }