diff --git a/js-assembler/assemble-helpers.rkt b/js-assembler/assemble-helpers.rkt index de835ca..45ed58c 100644 --- a/js-assembler/assemble-helpers.rkt +++ b/js-assembler/assemble-helpers.rkt @@ -99,7 +99,7 @@ (define (assemble-const stmt) (let: loop : String ([val : Any (Const-const stmt)]) (cond [(symbol? val) - (format "~s" (symbol->string val))] + (format "RUNTIME.makeSymbol(~s)" (symbol->string val))] [(pair? val) (format "RUNTIME.makePair(~a, ~a)" (loop (car val)) diff --git a/js-assembler/runtime-src/baselib-check.js b/js-assembler/runtime-src/baselib-check.js index 77701a3..a08d0cb 100644 --- a/js-assembler/runtime-src/baselib-check.js +++ b/js-assembler/runtime-src/baselib-check.js @@ -103,6 +103,10 @@ plt.baselib.ports.isOutputPort, 'output port'); + var checkSymbol = makeCheckArgumentType( + plt.baselib.symbols.isSymbol, + 'symbol'); + var checkString = makeCheckArgumentType( plt.baselib.strings.isString, 'string'); @@ -182,6 +186,7 @@ exports.checkOutputPort = checkOutputPort; exports.checkString = checkString; + exports.checkSymbol = checkSymbol; exports.checkProcedure = checkProcedure; exports.checkNumber = checkNumber; exports.checkReal = checkReal; diff --git a/js-assembler/runtime-src/baselib-symbols.js b/js-assembler/runtime-src/baselib-symbols.js index b294e68..409542d 100644 --- a/js-assembler/runtime-src/baselib-symbols.js +++ b/js-assembler/runtime-src/baselib-symbols.js @@ -48,11 +48,14 @@ var isSymbol = function(x) { return x instanceof Symbol; }; + var makeSymbol = function(s) { return Symbol.makeInstance(s); }; + ////////////////////////////////////////////////////////////////////// exports.Symbol = Symbol; + exports.makeSymbol = makeSymbol; exports.isSymbol = isSymbol; })(this['plt'].baselib); \ No newline at end of file diff --git a/js-assembler/runtime-src/runtime.js b/js-assembler/runtime-src/runtime.js index 3b9cfb1..01d34e6 100644 --- a/js-assembler/runtime-src/runtime.js +++ b/js-assembler/runtime-src/runtime.js @@ -23,6 +23,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; } var isList = plt.baselib.lists.isList; var isVector = plt.baselib.vectors.isVector; var isString = plt.baselib.strings.isString; + var isSymbol = plt.baselib.symbols.isSymbol; var isNonNegativeReal = plt.baselib.numbers.isNonNegativeReal; var equals = plt.baselib.equality.equals; @@ -40,6 +41,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; } var makeBignum = plt.baselib.numbers.makeBignum; var makeComplex = plt.baselib.numbers.makeComplex; + var makeSymbol = plt.baselib.symbols.makeSymbol; + var makeBox = plt.baselib.boxes.makeBox; var isBox = plt.baselib.boxes.isBox; @@ -106,6 +109,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; } var checkOutputPort = plt.baselib.check.checkOutputPort; var checkString = plt.baselib.check.checkString; + var checkSymbol = plt.baselib.check.checkSymbol; var checkProcedure = plt.baselib.check.checkProcedure; var checkNumber = plt.baselib.check.checkNumber; var checkReal = plt.baselib.check.checkReal; @@ -979,7 +983,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; } 1, function(MACHINE) { var firstArg = MACHINE.env[MACHINE.env.length-1]; - return plt.baselib.symbols.isSymbol(firstArg); + return isSymbol(firstArg); }); installPrimitiveProcedure( @@ -1659,86 +1663,6 @@ if(this['plt'] === undefined) { this['plt'] = {}; } - -// installPrimitiveProcedure( -// 'make-struct-field-accessor', -// makeList(2, 3), -// function(MACHINE) { - -// var accessor, fieldPos, fieldName; -// accessor = MACHINE.env[MACHINE.env.length-1]; -// fieldPos = MACHINE.env[MACHINE.env.length-2]; -// if (MACHINE.argcount === 2) { -// fieldName = 'field' + fieldPos; -// } else { -// fieldName = MACHINE.env[MACHINE.env.length-3]; -// } - -// testArgument(MACHINE, -// 'accessor procedure that requires a field index', -// function(x) { -// return (x instanceof types.StructAccessorProc && -// x.numParams > 1); -// }, -// accessor, -// 0, -// 'make-struct-field-accessor'); - -// testArgument(MACHINE, -// 'exact non-negative integer', -// isNatural, -// fieldPos, -// 'make-struct-field-accessor', -// 1) - -// testArgument(MACHINE, -// 'symbol or #f', -// function(x) { -// return x === false || isSymbol(x); -// }, -// 'make-struct-field-accessor', -// fieldName, -// 2); - - -// var procName = accessor.type.name + '-' fieldName; -// return new types.StructAccessorProc( -// accessor.type, -// procName, -// 1, -// false, -// false, -// function(MACHINE) { -// testArgument(MACHINE, -// 'struct:' + accessor.type.name, -// accessor.type.predicate, -// MACHINE.env[MACHINE.env.length - 1], -// procName, -// 0); -// return accessor.impl(x, fieldPos); -// }); - -// }); - - - - - - - - - - - - - - - - - - - - // Javascript-specific extensions. A small experiment. @@ -1937,7 +1861,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; } exports['makeRational'] = makeRational; exports['makeBignum'] = makeBignum; exports['makeComplex'] = makeComplex; - + exports['makeSymbol'] = makeSymbol; // Type predicates @@ -1948,6 +1872,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; } exports['isOutputStringPort'] = isOutputStringPort; exports['isBox'] = isBox; exports['isString'] = isString; + exports['isSymbol'] = isSymbol; exports['isNumber'] = isNumber; exports['isNatural'] = isNatural; exports['isReal'] = isReal; diff --git a/tests/test-browser-evaluate.rkt b/tests/test-browser-evaluate.rkt index 6bf1902..8be8563 100644 --- a/tests/test-browser-evaluate.rkt +++ b/tests/test-browser-evaluate.rkt @@ -41,6 +41,7 @@ EOF (syntax/loc #'stx (begin (printf "running test... ~s" (syntax->datum #'stx)) + (flush-output) (let ([result (evaluate s)]) (let ([output (evaluated-stdout result)]) (unless (string=? output exp) @@ -55,7 +56,8 @@ EOF (with-syntax ([stx stx]) (syntax/loc #'stx (begin - (printf "running test...") + (printf "running test... ~s" (syntax->datum #'stx)) + (flush-output) (let ([an-error-happened (with-handlers ([error-happened? (lambda (exn) @@ -106,14 +108,14 @@ EOF "25") ;; fixme: symbols need to be represented separately from strings. (test/exn (evaluate '(/ 3 'four)) - "Error: /: expected number as argument 2 but received \"four\"") + "Error: /: expected number as argument 2 but received four") (test '(display (- 1)) "-1") (test/exn '(- 'one) - "Error: -: expected number as argument 1 but received \"one\"") + "Error: -: expected number as argument 1 but received one") (test '(display (- 5 4)) "1")