Skip to content

Commit cb53511

Browse files
committed
runtime: Migrate more to RacketScript #44
- Most primitives from kernel.js migrated - paramz.js and unsafe.js to RacketScript - Fix bugs in kernel.rkt after migration - Add binary operator helper in kernel.rkt - interop: add undefined and null in language TODO: Should be value. Easy if we do id normalization earlier. - JSRequire fix for Racket 6.4 - Remove runtime/*.rkt from coverage. Can't execute this in Racket anyway
1 parent 45dc1d5 commit cb53511

File tree

19 files changed

+552
-1000
lines changed

19 files changed

+552
-1000
lines changed

racketscript-compiler/info.rkt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@
2525
(define test-omit-paths '("racketscript/browser.rkt"
2626
"racketscript/compiler/runtime/"))
2727
(define cover-omit-paths '("racketscript/browser.rkt"
28-
"racketscript/compiler/runtime/"))
28+
"racketscript/compiler/runtime/kernel.rkt"
29+
"racketscript/compiler/runtime/paramz.rkt"
30+
"racketscript/compiler/runtime/unsafe.rkt"))

racketscript-compiler/racketscript/compiler/assembler.rkt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
(when (ILBinaryOp? arg) (emit ")"))
7474
(unless last?
7575
(emit (~a oper))))]
76-
[(ILValue v) (assemble-value v out)]
7776
[(ILRef e s)
7877
(cond
7978
[(symbol? e) (emit (normalize-symbol e))]
@@ -117,9 +116,14 @@
117116
(assemble-expr type out)
118117
(emit ")")]
119118
[(ILTypeOf expr)
120-
(emit "tyopeof(")
119+
(emit "typeof(")
121120
(assemble-expr expr out)
122121
(emit ")")]
122+
[(ILValue v) (assemble-value v out)]
123+
[(ILNull)
124+
(emit "null")]
125+
[(ILUndefined)
126+
(emit "undefined")]
123127
[_ #:when (symbol? expr)
124128
(emit (~a (normalize-symbol expr)))]
125129
[_ (error "unsupported expr" (void))]))
@@ -466,6 +470,16 @@
466470
(ILBinaryOp '+ (list 'i 'j)))
467471
"arr[i+1][i+j]"
468472
"successive indexing")
473+
(check-expr (ILBinaryOp '+ '(a b))
474+
"a+b"
475+
"binary op")
476+
(check-expr (ILBinaryOp '\|\| '(a b))
477+
"a||b"
478+
"binary op")
479+
(check-expr (ILBinaryOp '\|\| (list (ILBinaryOp '&& '(a b))
480+
(ILBinaryOp '&& '(c d))))
481+
"(a&&b)||(c&&d)"
482+
"nested binary ops")
469483

470484
;;; ILRef -------------------------------------------------------------------
471485

racketscript-compiler/racketscript/compiler/expand.rkt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@
173173
[(#%plain-lambda formals . body)
174174
(define fabsyn (formals->absyn #'formals))
175175
(PlainLambda fabsyn (map to-absyn (syntax->list #'body)))]
176-
[(define-values (name) (#%plain-app (~datum #%js-ffi) (~datum 'require) 'mod))
176+
[(define-values (name)
177+
(#%plain-app (~datum #%js-ffi) (quote require) (quote mod:str)))
177178
;; HACK: Special case for JSRequire
178179
(JSRequire (syntax-e #'name) (syntax-e #'mod))]
179180
[(define-values (id ...) b)
@@ -240,9 +241,6 @@
240241
(match-let ([(cons (app last mod) (? symbol? id)) path-to-symbol])
241242
(values id mod))]))
242243

243-
;; For compiling #%kernel (or primitive module) we may end
244-
;; up thinking that's id is imported as we are actually
245-
;; overriding the module. Don't make it happen.
246244
(register-ident-use! effective-mod effective-id)
247245
(ImportedIdent effective-id effective-mod)])])]
248246
[(define-syntaxes (i ...) b) #f]

racketscript-compiler/racketscript/compiler/il-analyze.rkt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@
100100
[(ILNew v)
101101
(ILNew (cast (handle-expr v) (U Symbol ILRef ILIndex ILApp)))]
102102
[(ILValue v) e]
103+
[(ILUndefined) e]
104+
[(ILNull) e]
103105
[(? symbol? v) v]))
104106

105107
(: handle-stm (-> ILStatement ILResult))
@@ -547,6 +549,8 @@
547549
[(ILTypeOf expr)
548550
(ILTypeOf (handle-expr/general expr))]
549551
[(ILValue v) e]
552+
[(ILUndefined) e]
553+
[(ILNull) e]
550554
[(ILNew v) e]
551555
[(? symbol? v) e]))
552556

@@ -771,6 +775,8 @@
771775
(match-define (list _ f-free) (find fieldexpr defs))
772776
(list (set) (set-union e-free f-free))]
773777
[(ILValue v) (list (set) (set))]
778+
[(ILUndefined) (list (set) (set))]
779+
[(ILNull) (list (set) (set))]
774780
[(ILNew e) (find e defs)]
775781
[(? symbol? v)
776782
(list (set)
@@ -852,6 +858,8 @@
852858
[(ILIndex expr fieldexpr) (or (has-application? expr)
853859
(has-application? fieldexpr))]
854860
[(ILValue _) #f]
861+
[(ILUndefined) #f]
862+
[(ILNull) #f]
855863
[(ILNew _) #t]
856864
[(ILInstanceOf expr type) (or (has-application? expr)
857865
(has-application? type))]
@@ -969,6 +977,8 @@
969977
(match-define (list f-used _) (used+defined/statement fieldexpr))
970978
(list (set-union e-used f-used) (set))]
971979
[(ILValue v) (list (set) (set))]
980+
[(ILUndefined) (list (set) (set))]
981+
[(ILNull) (list (set) (set))]
972982
[(ILNew e) (used+defined/statement e)]
973983
[(? symbol? v)
974984
(list (set v) (set))]))
@@ -1076,6 +1086,8 @@
10761086
[(ILInstanceOf expr* type) (ILInstanceOf (flatten-if-else/expr expr*)
10771087
(flatten-if-else/expr type))]
10781088
[(ILTypeOf expr) (ILTypeOf (flatten-if-else/expr expr))]
1089+
[(? ILUndefined? v) v]
1090+
[(? ILNull? v) v]
10791091
[(? ILValue? v) v]
10801092
[(? symbol? s) s]))
10811093

racketscript-compiler/racketscript/compiler/il.rkt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
(ILInstanceOf [expr : ILExpr]
5757
[type : ILExpr])
5858
(ILTypeOf [expr : ILExpr])
59+
60+
;; Should be ideally in values
61+
(ILNull)
62+
(ILUndefined)
5963
Symbol]
6064

6165
[ILStatement ILExpr

racketscript-compiler/racketscript/compiler/js-support/traceur/gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ gulp.task('build', ['copy-hamt'], function() {
1616
return gulp.src('modules/' + target)
1717
.pipe(traceur({modules: 'inline'}))
1818
.pipe(concat('compiled.js'))
19-
.pipe(uglify())
19+
//.pipe(uglify())
2020
.pipe(gulp.dest('dist'));
2121
});
2222

racketscript-compiler/racketscript/compiler/main.rkt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@
220220

221221
(put-to-pending! (path->complete-path (main-source-file)))
222222
(put-to-pending! '#%kernel)
223+
(put-to-pending! '#%unsafe)
224+
(put-to-pending! '#%paramz)
223225

224226
(let loop ()
225227
(cond

0 commit comments

Comments
 (0)