view 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
line wrap: on
line source

#{
	main <- {
		print: "foo: " . 42 . "\n"
		print: (string: (length: "foo" . "bar")) . "\n"
		print: (string: ("foobarbaz" find: "foo" else: { "not found" })) . "\n"
		print: (string: ("foobarbaz" find: "bar" else: { "not found" })) . "\n"
		print: (string: ("foobarbaz" find: "baz" else: { "not found" })) . "\n"
		print: (string: ("foobarbaz" find: "qux" else: { "not found" })) . "\n"

		print: ("foobarbaz" from: 3) . "\n"
		print: ("foobarbaz" from: 3 withLength: 3) . "\n"

		foreach: ("foo,bar,baz,qux" splitOn: ",") :idx val {
			print: val . "\n"
		}

		res <- "foobarbaz" partitionOn: "bar"
		print: "Before: " . (res before) . "\n"
		print: "After: " . (res after) . "\n"

		print: (string: ("12abcDEF" parseHex32)) . "\n"
		print: (string: ("FFFFFFFFFF" parseHex64)) . "\n"
	}
}