Skip to content

Commit

Permalink
small bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Rowland committed Aug 7, 2012
1 parent d817bf9 commit b3d43c2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 43 deletions.
2 changes: 0 additions & 2 deletions js-runtime/lib/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -871,8 +871,6 @@ var selectProcedureByArity = function(aState, n, procValue, operands) {
if ( !types.isFunction(procValue) ) {
var argStr = getArgStr('; arguments were:');
var positionStack = state.captureCurrentContinuationMarks(aState).ref(types.symbol('moby-application-position-key'));

console.log("positionStack is ", positionStack);

var locationList = positionStack[positionStack.length - 1];
var locs = locationList;
Expand Down
2 changes: 0 additions & 2 deletions js-runtime/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,9 @@ var helpers = {};
if((! (state.isState(args[i])))
&&
(!((args[i].name !== undefined) && args[i].name === ""))) {
if(args[i].name) console.log("args[i].name is ", args[i].name);
actualArgs.push(args[i]);
}
}
console.log("now, actualArgs is ", actualArgs);
window.wtf = args[2];
for(i = 0; i < actualArgs.length; i++){
if(! (locs.isEmpty())){
Expand Down
4 changes: 0 additions & 4 deletions servlet-htdocs/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,9 @@ var helpers = {};
if((! (state.isState(args[i])))
&&
(!((args[i].name !== undefined) && args[i].name === ""))) {
if(args[i].name) console.log("args[i].name is ", args[i].name);
actualArgs.push(args[i]);
}
}
console.log("now, actualArgs is ", actualArgs);
window.wtf = args[2];
for(i = 0; i < actualArgs.length; i++){
if(! (locs.isEmpty())){
Expand Down Expand Up @@ -20784,8 +20782,6 @@ var selectProcedureByArity = function(aState, n, procValue, operands) {
if ( !types.isFunction(procValue) ) {
var argStr = getArgStr('; arguments were:');
var positionStack = state.captureCurrentContinuationMarks(aState).ref(types.symbol('moby-application-position-key'));

console.log("positionStack is ", positionStack);

var locationList = positionStack[positionStack.length - 1];
var locs = locationList;
Expand Down
65 changes: 30 additions & 35 deletions src/compiler/helpers.ss
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#lang racket/base
#lang s-exp "lang.ss"

(require racket/local
racket/contract
(only-in racket/bool true false)
(only-in racket/list empty? rest first second empty third))
(require "rbtree.ss")
(require "../collects/moby/runtime/stx.ss")
(require "../collects/moby/runtime/error-struct.ss")

(define pair? cons?)

;; A program is a (listof (or/c defn? expr? library-require? provide-statement? require-permission?))

(define (list? datum)
(or (empty? datum)
(and
(pair? datum)
(list? (rest datum)))))


;; symbol<: symbol symbol -> boolean
Expand Down Expand Up @@ -176,11 +179,11 @@
(stx-begins-with? an-sexp 'require))


;; java-identifiers: (hashof symbol boolean)
;; java-identifiers: (rbtreeof symbol boolean)
(define java-identifiers
(foldl (lambda (sym a-hash)
(hash-set a-hash sym true))
(make-immutable-hash)
(foldl (lambda (sym an-rbtree)
(rbtree-insert symbol< an-rbtree sym true))
empty-rbtree

'(abstract continue for new switch
assert default goto package synchronized
Expand All @@ -197,11 +200,11 @@
debugger)))


;; special-character-mappings: (hashof char string)
;; special-character-mappings: (rbtreeof char string)
(define special-character-mappings
(foldl (lambda (ch+translation a-hash)
(hash-set a-hash (first ch+translation) (second ch+translation)))
(make-immutable-hash)
(foldl (lambda (ch+translation an-rbtree)
(rbtree-insert char<? an-rbtree (first ch+translation) (second ch+translation)))
empty-rbtree
'((#\- "_dash_")
(#\_ "_underline_")
(#\? "_question_")
Expand All @@ -227,16 +230,16 @@
;; Special character mappings for identifiers.
(define (translate-special-character ch)
(cond
[(hash-has-key? special-character-mappings ch)
(hash-ref special-character-mappings ch)]
[(cons? (rbtree-lookup char<? special-character-mappings ch))
(second (rbtree-lookup char<? special-character-mappings ch))]
[else
(string ch)]))


;; identifier->munged-java-identifier: symbol -> symbol
(define (identifier->munged-java-identifier an-id)
(cond
[(hash-has-key? java-identifiers an-id)
[(cons? (rbtree-lookup symbol< java-identifiers an-id))
(string->symbol (string-append "_" (symbol->string an-id) "_"))]
[else
(local [(define (maybe-prepend-hyphen chars)
Expand Down Expand Up @@ -274,6 +277,16 @@
(remove-leading-whitespace/list (string->list a-str)))


;; take: (listof X) number -> (listof X)
;; Produces a list of the first n elmeents of a-list.
(define (take a-list n)
(cond
[(= n 0)
empty]
[else
(cons (first a-list)
(take (rest a-list) (sub1 n)))]))


;; list-tail: (listof X) number -> (listof X)
;; Produces a list of the last n elmeents in a-list.
Expand Down Expand Up @@ -366,11 +379,6 @@
(define body (third (stx-e a-definition)))]
(f-define-values ids body))]



;; FIXME: add more error productions as necessary to get
;; reasonable error messages.

[(stx-begins-with? a-definition 'define)
(if (define-var? a-definition)
(find-defn-var-error a-definition)
Expand All @@ -379,20 +387,6 @@
[(stx-begins-with? a-definition 'define-struct)
(handle-defn-struct-error a-definition)]


;(raise (make-moby-error
; (stx-loc a-definition)
; (make-moby-error-type:generic-syntactic-error
; "define expects either an identifier and a body: (define answer 42), or a function header and body: (define (double x ) (* x 2))"
; (list))))]
;
;[(stx-begins-with? a-definition 'define-struct)
; (raise (make-moby-error
; (stx-loc a-definition)
; (make-moby-error-type:generic-syntactic-error
; "define-struct expects an identifier and a list of fields. i.e. (define-struct pizza (dough sauce toppings))"
; (list))))]

[(stx-begins-with? a-definition 'define-values)
(handle-defn-values-error a-definition)]

Expand Down Expand Up @@ -662,6 +656,7 @@
[require-permission? (any/c . -> . boolean?)]
[library-require? (any/c . -> . boolean?)]
[provide-statement? (any/c . -> . boolean?)]
[take ((listof any/c) number? . -> . (listof any/c))]
[list-tail ((listof any/c) number? . -> . (listof any/c))]

[expression<? (expression? expression? . -> . boolean?)]
Expand Down

0 comments on commit b3d43c2

Please sign in to comment.