in the middle of trying to compile racket/base and see how far I can get

This commit is contained in:
Danny Yoo 2011-05-23 12:58:55 -04:00
parent a695eafa15
commit 3b61f88d27
7 changed files with 79 additions and 6 deletions

View File

@ -12,12 +12,25 @@
(provide (rename-out [-compile compile]) (provide (rename-out [-compile compile])
compile-general-procedure-call compile-general-procedure-call
current-warn-unimplemented-kernel-primitive
append-instruction-sequences) append-instruction-sequences)
(: default-warn-unimplemented-kernel-primitive (Symbol -> Void))
(define (default-warn-unimplemented-kernel-primitive id)
(printf "WARNING: Primitive Kernel Value ~s has not been implemented\n"
id))
(: current-warn-unimplemented-kernel-primitive (Parameterof (Symbol -> Void)))
(define current-warn-unimplemented-kernel-primitive (make-parameter default-warn-unimplemented-kernel-primitive))
(: -compile (Expression Target Linkage -> (Listof Statement))) (: -compile (Expression Target Linkage -> (Listof Statement)))
;; Generates the instruction-sequence stream. ;; Generates the instruction-sequence stream.
;; Note: the toplevel generates the lambda body streams at the head, and then the ;; Note: the toplevel generates the lambda body streams at the head, and then the
@ -2017,7 +2030,6 @@
(let ([id (PrimitiveKernelValue-id exp)]) (let ([id (PrimitiveKernelValue-id exp)])
(cond (cond
[(KernelPrimitiveName? id) [(KernelPrimitiveName? id)
(let ([singular-context-check (emit-singular-context linkage)]) (let ([singular-context-check (emit-singular-context linkage)])
;; Compiles constant values. ;; Compiles constant values.
(end-with-linkage linkage (end-with-linkage linkage
@ -2027,9 +2039,10 @@
`(,(make-AssignImmediateStatement target exp) `(,(make-AssignImmediateStatement target exp)
singular-context-check)))))] singular-context-check)))))]
[else [else
(error 'unimplemented-kernel-primitive ((current-warn-unimplemented-kernel-primitive) id)
"Primitive Kernel Value ~s has not been implemented" (make-instruction-sequence
id)]))) `(,(make-PerformStatement (make-RaiseUnimplementedPrimitiveError! id))))])))

View File

@ -388,6 +388,11 @@
#:transparent) #:transparent)
;; Raise a runtime error if we hit a use of an unimplemented kernel primitive.
(define-struct: RaiseUnimplementedPrimitiveError! ([name : Symbol])
#:transparent)
;; Changes over the control located at the given argument from the structure in env[1] ;; Changes over the control located at the given argument from the structure in env[1]
@ -426,6 +431,7 @@
RaiseContextExpectedValuesError! RaiseContextExpectedValuesError!
RaiseArityMismatchError! RaiseArityMismatchError!
RaiseOperatorApplicationError! RaiseOperatorApplicationError!
RaiseUnimplementedPrimitiveError!
RestoreEnvironment! RestoreEnvironment!
RestoreControl! RestoreControl!

View File

@ -125,6 +125,12 @@
(format "RUNTIME.raiseOperatorApplicationError(MACHINE, ~a);" (format "RUNTIME.raiseOperatorApplicationError(MACHINE, ~a);"
(assemble-oparg (RaiseOperatorApplicationError!-operator op)))] (assemble-oparg (RaiseOperatorApplicationError!-operator op)))]
[(RaiseUnimplementedPrimitiveError!? op)
(format "RUNTIME.raiseUnimplementedPrimitiveError(MACHINE, ~s);"
(symbol->string (RaiseUnimplementedPrimitiveError!-name op)))]
[(InstallModuleEntry!? op) [(InstallModuleEntry!? op)
(format "MACHINE.modules[~s]=new RUNTIME.ModuleRecord(~s, ~a);" (format "MACHINE.modules[~s]=new RUNTIME.ModuleRecord(~s, ~a);"
(symbol->string (ModuleName-name (InstallModuleEntry!-path op))) (symbol->string (ModuleName-name (InstallModuleEntry!-path op)))

View File

@ -303,6 +303,27 @@
MACHINE.argcount + " values")); MACHINE.argcount + " values"));
}; };
var raiseArityMismatchError = function(MACHINE, expected, received) {
raise(MACHINE,
new Error("expected " + expected +
" values, received " +
received + " values"));
};
var raiseOperatorApplicationError = function(MACHINE, operator) {
raise(MACHINE,
new Error("not a procedure: " + expected +
operator));
};
var raiseUnimplementedPrimitiveError = function(MACHINE, name) {
raise(MACHINE,
new Error("unimplemented kernel procedure: " + name))
};
// captureControl implements the continuation-capturing part of // captureControl implements the continuation-capturing part of
// call/cc. It grabs the control frames up to (but not including) the // call/cc. It grabs the control frames up to (but not including) the
@ -1199,6 +1220,9 @@
exports['testArity'] = testArity; exports['testArity'] = testArity;
exports['raise'] = raise; exports['raise'] = raise;
exports['raiseContextExpectedValuesError'] = raiseContextExpectedValuesError; exports['raiseContextExpectedValuesError'] = raiseContextExpectedValuesError;
exports['raiseArityMismatchError'] = raiseArityMismatchError;
exports['raiseOperatorApplicationError'] = raiseOperatorApplicationError;
exports['raiseUnimplementedPrimitiveError'] = raiseUnimplementedPrimitiveError;
exports['captureControl'] = captureControl; exports['captureControl'] = captureControl;

View File

@ -30,6 +30,7 @@
'cadr 'cadr
'caddr 'caddr
'list 'list
'list*
'list->vector 'list->vector
'vector->list 'vector->list
'vector 'vector
@ -64,6 +65,16 @@
'map 'map
'for-each 'for-each
'current-print 'current-print
;; These are necessary to get racket/base compiled
;; and running
'raise-type-error
'hash-map
'abort-current-continuation
'raise
'list?
'keyword<?
)) ))
(define-predicate KernelPrimitiveName? KernelPrimitiveName) (define-predicate KernelPrimitiveName? KernelPrimitiveName)

View File

@ -10,6 +10,7 @@
"get-dependencies.rkt" "get-dependencies.rkt"
"js-assembler/assemble.rkt" "js-assembler/assemble.rkt"
"js-assembler/get-runtime.rkt" "js-assembler/get-runtime.rkt"
"lexical-structs.rkt"
"quote-cdata.rkt" "quote-cdata.rkt"
racket/runtime-path racket/runtime-path
racket/port racket/port
@ -61,7 +62,14 @@
[(eq? ast #f) [(eq? ast #f)
sources] sources]
[else [else
sources])) (let* ([dependent-module-names (get-dependencies ast)]
[paths
(map ModuleName-real-path
(filter (lambda (mp) (and (path? (ModuleName-real-path mp))
(should-follow?
(path? (ModuleName-real-path mp)))))
dependent-module-names))])
(append paths sources))]))
(let loop ([sources sources]) (let loop ([sources sources])
(cond (cond
@ -71,6 +79,7 @@
[(hash-has-key? visited (first sources)) [(hash-has-key? visited (first sources))
(loop (rest sources))] (loop (rest sources))]
[else [else
(printf "visiting ~s\n" (first sources))
(hash-set! visited (first sources) #t) (hash-set! visited (first sources) #t)
(let-values ([(ast stmts) (get-ast-and-statements (first sources))]) (let-values ([(ast stmts) (get-ast-and-statements (first sources))])
(assemble/write-invoke stmts op) (assemble/write-invoke stmts op)

View File

@ -451,6 +451,10 @@
(error 'step "expected procedure, given ~a" (error 'step "expected procedure, given ~a"
(evaluate-oparg m (RaiseOperatorApplicationError!-operator op)))] (evaluate-oparg m (RaiseOperatorApplicationError!-operator op)))]
[(RaiseUnimplementedPrimitiveError!? op)
(error 'step "Unimplemented kernel procedure ~a"
(RaiseUnimplementedPrimitiveError!-name op))]
[(InstallModuleEntry!? op) [(InstallModuleEntry!? op)
(printf "installing module ~s\n" (printf "installing module ~s\n"