From 570ad833711f97867563cb10af5ae3d489b590db Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Sun, 3 Jul 2011 21:09:54 -0400 Subject: [PATCH] structures finally look like they might be doing something --- js-assembler/runtime-src/runtime.js | 9 ++++++--- tests/more-tests/run-more-tests.rkt | 2 +- tests/more-tests/simple-structs.expected | 3 +++ tests/more-tests/simple-structs.rkt | 23 ++++++++++++----------- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/js-assembler/runtime-src/runtime.js b/js-assembler/runtime-src/runtime.js index 75d48cd..525d6ce 100644 --- a/js-assembler/runtime-src/runtime.js +++ b/js-assembler/runtime-src/runtime.js @@ -2096,7 +2096,6 @@ if(this['plt'] === undefined) { this['plt'] = {}; } //immutables, guard); - console.log('constructor', name, superType, initFieldCount); var constructorValue = makePrimitiveProcedure( constructorName, @@ -2127,6 +2126,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; } MACHINE.env[MACHINE.env.length - 1], jsnums.toFixnum(MACHINE.env[MACHINE.env.length - 2])); }); + accessorValue.structType = structType; var mutatorValue = makePrimitiveProcedure( @@ -2139,6 +2139,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; } jsnums.toFixnum(MACHINE.env[MACHINE.env.length - 2]), MACHINE.env[MACHINE.env.length - 3]); }); + mutatorValue.structType = structType; finalizeClosureCall(MACHINE, @@ -2169,7 +2170,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; } makeList(2, 3), function(MACHINE){ // FIXME: typechecks - var structType = MACHINE.env[MACHINE.env.length - 1]; + // We must guarantee that the ref argument is good. + var structType = MACHINE.env[MACHINE.env.length - 1].structType; var index = MACHINE.env[MACHINE.env.length - 2]; var name; if (MACHINE.argcount === 3) { @@ -2194,7 +2196,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; } makeList(2, 3), function(MACHINE){ // FIXME: typechecks - var structType = MACHINE.env[MACHINE.env.length - 1]; + // We must guarantee that the set! argument is good. + var structType = MACHINE.env[MACHINE.env.length - 1].structType; var index = MACHINE.env[MACHINE.env.length - 2]; var name; if (MACHINE.argcount === 3) { diff --git a/tests/more-tests/run-more-tests.rkt b/tests/more-tests/run-more-tests.rkt index 9730998..93a6f06 100644 --- a/tests/more-tests/run-more-tests.rkt +++ b/tests/more-tests/run-more-tests.rkt @@ -10,4 +10,4 @@ (test "conform.rkt") (test "sk-generator.rkt") (test "sk-generator-2.rkt") -#;(test "simple-structs.rkt") \ No newline at end of file +(test "simple-structs.rkt") \ No newline at end of file diff --git a/tests/more-tests/simple-structs.expected b/tests/more-tests/simple-structs.expected index b944734..85f0fa0 100644 --- a/tests/more-tests/simple-structs.expected +++ b/tests/more-tests/simple-structs.expected @@ -1,2 +1,5 @@ 3 4 +3 +4 +5 diff --git a/tests/more-tests/simple-structs.rkt b/tests/more-tests/simple-structs.rkt index 8b6a0f1..b98e47a 100644 --- a/tests/more-tests/simple-structs.rkt +++ b/tests/more-tests/simple-structs.rkt @@ -1,16 +1,17 @@ #lang planet dyoo/whalesong -(define-struct p (f r)) - - -struct:p -make-p -p-f -p-r -p? +(define-struct pair (f r)) +(define-struct color (r g b)) -(define p1 (make-p 3 4)) -(p-f p1) -(p-r p1) + +(define p1 (make-pair 3 4)) +(pair-f p1) +(pair-r p1) + + + +(color-r (make-color 3 4 5)) +(color-g (make-color 3 4 5)) +(color-b (make-color 3 4 5)) \ No newline at end of file