changeset 79:7f635666c73d

Add hash and int32 messages to string. Add hash message to int32. Update compile script
author Mike Pavone <pavone@retrodev.com>
date Mon, 16 Jul 2012 01:10:12 -0700
parents abc6f3d644a4
children cbc92ee13f35
files cbackend.js compile samples/hash.tp
diffstat 3 files changed, 41 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/cbackend.js	Sun Jul 15 18:11:00 2012 -0700
+++ b/cbackend.js	Mon Jul 16 01:10:12 2012 -0700
@@ -448,6 +448,12 @@
 			'return &(str->header);'
 		]
 	});
+	int32.addMessage('hash', {
+		vars: {},
+		lines: [
+			'return &(self->header);'
+		]
+	});
 	return int32;
 }
 
@@ -592,6 +598,29 @@
 			'return &(intret->header);'
 		]
 	});
+	string.addMessage('int32', {
+		vars: {intret: 'obj_int32 *'},
+		lines: [
+			'intret = (obj_int32 *)make_object(&obj_int32_meta, NULL, 0);',
+			'intret->num = atoi(self->data);',
+			'return &(intret->header);'
+		]
+	});
+	string.addMessage('hash', {
+		vars: {intret: 'obj_int32 *', i: 'uint32_t'},
+		lines: [
+			'intret = (obj_int32 *)make_object(&obj_int32_meta, NULL, 0);',
+			'intret->num = 0;',
+			'if (self->bytes) {',
+			'	intret->num = self->data[0] << 7;',
+			'	for (i = 0; i < self->bytes; i++) {',
+			'		intret->num = (1000003 * intret->num) ^ self->data[i];',
+			'	}',
+			'	intret->num = intret->num ^ self->bytes;',
+			'}',
+			'return &(intret->header);'
+		]
+	});
 	return string;
 }
 
--- a/compile	Sun Jul 15 18:11:00 2012 -0700
+++ b/compile	Mon Jul 16 01:10:12 2012 -0700
@@ -6,7 +6,7 @@
 	rm "$cname"
 fi
 
-d8 tpc.js -- $1 > $cname
+./tpc $1 -o $cname
 
 if test ! -s "$cname"; then
 	echo "Compilation to C failed"
@@ -15,4 +15,4 @@
 
 bin=`echo $1 | sed s/\.tp//`
 shift
-gcc $@ -o $bin $cname runtime/object.c
+gcc $@ -o $bin $cname runtime/object.c -lgc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/samples/hash.tp	Mon Jul 16 01:10:12 2012 -0700
@@ -0,0 +1,10 @@
+#{
+	main <- {
+		print: "hash of 'foo' is " . ("foo" hash) . "\n"
+		print: "hash of 'bar' is " . ("bar" hash) . "\n"
+		print: "hash of 'foobar' is " . ("foobar" hash) . "\n"
+		print: "hash of 1 is " . (1 hash) . "\n"
+		print: "hash of 2 is " . (2 hash) . "\n"
+		print: "hash of 3 is " . (3 hash) . "\n"
+	}
+}