Browse files

reorganizing

  • Loading branch information...
1 parent 3dd9c53 commit 67a368e1eb6a70120bbeda89fbd37ce959d6f6ed Danny Yoo committed Jun 13, 2011
View
0 bf/README → README
File renamed without changes.
View
12 bf/lang/reader.rkt
@@ -1,12 +0,0 @@
-#lang s-exp syntax/module-reader
-(planet dyoo/bf/language)
-#:read my-read
-#:read-syntax my-read-syntax
-
-(require "../parser.rkt")
-
-(define (my-read in)
- (syntax->datum (my-read-syntax #f in)))
-
-(define (my-read-syntax src in)
- (parse-expr src in))
View
2 examples/beer.rkt
@@ -1,4 +1,4 @@
-#lang planet dyoo/brainfudge
+#lang planet dyoo/bf
##########################
###
### Severely updated version!
View
2 examples/cat.rkt
@@ -1,2 +1,2 @@
-#lang planet dyoo/brainfudge
+#lang planet dyoo/bf
,[.[-],]
View
2 examples/hello-world.rkt
@@ -1,4 +1,4 @@
-#lang planet dyoo/brainfudge
+#lang planet dyoo/bf
+++++ +++++ initialize counter (cell #0) to 10
[ use loop to set the next four cells to 70/100/30/10
View
0 bf/hello.rkt → examples/hello.rkt
File renamed without changes.
View
2 bf/hello2.rkt → examples/hello2.rkt
@@ -1,4 +1,4 @@
-#lang planet dyoo/bf:1:1
+#lang planet dyoo/bf
++++++[>++++++++++++<-]>.
>++++++++++[>++++++++++<-]>+.
+++++++..+++.>++++[>+++++++++++<-]>.
View
145 examples/manually-translated-hello-world.rkt
@@ -1,145 +0,0 @@
-#lang racket/base
-(require "../lang/semantics.rkt")
-
-#|
-
-A manual translation of the hello world program, just to make sure I
-have the right understanding of the semantics. I hand-translate:
-
-
-
-+++++ +++++ initialize counter (cell #0) to 10
-[ use loop to set the next four cells to 70/100/30/10
- > +++++ ++ add 7 to cell #1
- > +++++ +++++ add 10 to cell #2
- > +++ add 3 to cell #3
- > + add 1 to cell #4
- <<<< - decrement counter (cell #0)
-]
-
-
-> ++ . print 'H'
-> + . print 'e'
-+++++ ++ . print 'l'
-. print 'l'
-+++ . print 'o'
-> ++ . print ' '
-<< +++++ +++++ +++++ . print 'W'
-> . print 'o'
-+++ . print 'r'
------ - . print 'l'
------ --- . print 'd'
-> + . print '!'
-> . print '\n
-
-
-
-into the program below:
-
-|#
-
-
-
-(toplevel
-
- (increment-byte)
- (increment-byte)
- (increment-byte)
- (increment-byte)
- (increment-byte)
- (increment-byte)
- (increment-byte)
- (increment-byte)
- (increment-byte)
- (increment-byte)
-
-
-
- ;; This is a translation of the loop.
- (loop (increment-data-pointer)
- (increment-byte)
- (increment-byte)
- (increment-byte)
- (increment-byte)
- (increment-byte)
-
- (increment-byte)
- (increment-byte)
-
- (increment-data-pointer)
- (increment-byte)
- (increment-byte)
- (increment-byte)
- (increment-byte)
- (increment-byte)
-
- (increment-byte)
- (increment-byte)
- (increment-byte)
- (increment-byte)
- (increment-byte)
-
- (increment-data-pointer)
- (increment-byte)
- (increment-byte)
- (increment-byte)
-
- (increment-data-pointer)
- (increment-byte)
-
- (decrement-data-pointer)
- (decrement-data-pointer)
- (decrement-data-pointer)
- (decrement-data-pointer)
-
- (decrement-byte))
-
-
-
- ;; > ++ . print 'H'
- (increment-data-pointer) (increment-byte) (increment-byte) (output-byte)
-
- ;; > + . print 'e'
- (increment-data-pointer) (increment-byte) (output-byte)
-
- ;; +++++ ++ . print 'l'
- (increment-byte)(increment-byte)(increment-byte)(increment-byte)(increment-byte) (increment-byte)(increment-byte) (output-byte)
-
- ;; . print 'l'
- (output-byte)
-
-
- ;; +++ . print 'o'
- (increment-byte) (increment-byte) (increment-byte) (output-byte)
-
- ;; > ++ . print ' '
- (increment-data-pointer) (increment-byte) (increment-byte) (output-byte)
-
-
- ;; << +++++ +++++ +++++ . print 'W'
- (decrement-data-pointer) (decrement-data-pointer)
- (increment-byte) (increment-byte)(increment-byte)(increment-byte)(increment-byte)
- (increment-byte) (increment-byte)(increment-byte)(increment-byte)(increment-byte)
- (increment-byte) (increment-byte)(increment-byte)(increment-byte)(increment-byte)
- (output-byte)
-
- ;; > . print 'o'
- (increment-data-pointer) (output-byte)
-
- ;; +++ . print 'r'
- (increment-byte) (increment-byte) (increment-byte) (output-byte)
-
- ;; ----- - . print 'l'
- (decrement-byte) (decrement-byte) (decrement-byte) (decrement-byte) (decrement-byte)
- (decrement-byte) (output-byte)
-
- ;; ----- --- . print 'd'
- (decrement-byte) (decrement-byte) (decrement-byte) (decrement-byte) (decrement-byte)
- (decrement-byte) (decrement-byte) (decrement-byte) (output-byte)
-
-
- ;; > + . print '!'
- (increment-data-pointer) (increment-byte) (output-byte)
-
- ;; > . print '\n
- (increment-data-pointer) (output-byte))
View
2 examples/prime.rkt
@@ -1,4 +1,4 @@
-#lang planet dyoo/brainfudge
+#lang planet dyoo/bf
===================================================================
======================== OUTPUT STRING ============================
===================================================================
View
12 info.rkt
@@ -1,13 +1,13 @@
#lang setup/infotab
-
-(define scribblings '(("manual.scrbl")))
-(define name "brainfudge")
+(define name "bf: a brainf*ck compiler for Racket")
(define categories '(devtools))
(define can-be-loaded-with 'all)
(define required-core-version "5.1.1")
-(define version "1.1")
+(define version "1.2")
(define repositories '("4.x"))
+(define scribblings '())
+(define primary-file "language.rkt")
(define blurb
- '("Program in Brainf*ck; a small example of adding a language into Racket"))
+ '("Provides support for the brainf*ck language."))
(define release-notes
- '((p "Initial public release.")))
+ '((p "First release")))
View
31 lang/reader.rkt
@@ -1,35 +1,12 @@
#lang s-exp syntax/module-reader
-(planet dyoo/brainfudge/lang/language)
+(planet dyoo/bf/language)
#:read my-read
#:read-syntax my-read-syntax
+(require "../parser.rkt")
-;; Now that we have a parser, let't provide the two functions that a
-;; language reader module needs to define. These are the read and
-;; read-syntax functions.
-(require "parser.rkt")
-
-
-
-;; my-read: input-port -> s-expression
(define (my-read in)
- (syntax->datum
- (my-read-syntax #f in)))
+ (syntax->datum (my-read-syntax #f in)))
-
-
-;; my-read-syntax: any input-port -> syntax-object
-;;
(define (my-read-syntax src in)
- ;; Note: we're ignoring our src, but if our parser were a bit nicer,
- ;; it would also keep track of the src in the resulting syntax
- ;; objects.
-
- ;; We also need to return eof once we've exhausted the token stream,
- ;; so let's do so.
- (let ([token-stream (get-tokens in)])
- (cond
- [(eof-object? (peek token-stream))
- eof]
- [else
- (parse-toplevel token-stream)])))
+ (parse-expr src in))
View
0 bf/language.rkt → language.rkt
File renamed without changes.
View
22 manual.scrbl
@@ -540,7 +540,7 @@ For example,
20
32
5)))]
-The first argument that we pass into @racket[datum->syntax] lets us tells Racket any
+The first argument that we pass into @racket[datum->syntax] lets us tell Racket any
lexical-scoping information that we know about the datum, but in this case, we don't have
any on hand, so we just give it @racket[#f]. Let's look at the structure of this syntax object.
@interaction[#:eval my-evaluator
@@ -767,7 +767,25 @@ $ ls -l bf.plt
}|
There are a few warnings, because we haven't defined an @filepath{info.rkt} which provides metadata
-about our package. Good, diligent citizens would @link["http://docs.racket-lang.org/planet/Developing_Packages_for_PLaneT.html#(part._.Create_an__info_rkt__.File__.Optional_)"]{do so}.
+about our package. Good, diligent citizens would @link["http://docs.racket-lang.org/planet/Developing_Packages_for_PLaneT.html#(part._.Create_an__info_rkt__.File__.Optional_)"]{write an @filepath{info.rkt} file}, so let's write one.
+@filebox["info.rkt"]{
+@codeblock|{
+#lang setup/infotab
+(define name "bf: a brainf*ck compiler for Racket")
+(define categories '(devtools))
+(define can-be-loaded-with 'all)
+(define required-core-version "5.1.1")
+(define version "1.0")
+(define repositories '("4.x"))
+(define scribblings '())
+(define primary-file "language.rkt")
+(define blurb
+ '("Provides support for the brainf*ck language."))
+(define release-notes
+ '((p "First release")))
+ }|}
+
+
Before we upload the package, let's make sure the @filepath{bf.plt} package works for us locally. We'll simulate an installation. First, let's break the development link.
View
13 old-lang/info.rkt
@@ -0,0 +1,13 @@
+#lang setup/infotab
+
+(define scribblings '(("manual.scrbl")))
+(define name "brainfudge")
+(define categories '(devtools))
+(define can-be-loaded-with 'all)
+(define required-core-version "5.1.1")
+(define version "1.1")
+(define repositories '("4.x"))
+(define blurb
+ '("Program in Brainf*ck; a small example of adding a language into Racket"))
+(define release-notes
+ '((p "Initial public release.")))
View
0 lang/language.rkt → old-lang/language.rkt
File renamed without changes.
View
0 lang/parser.rkt → old-lang/parser.rkt
File renamed without changes.
View
35 old-lang/reader.rkt
@@ -0,0 +1,35 @@
+#lang s-exp syntax/module-reader
+(planet dyoo/brainfudge/lang/language)
+#:read my-read
+#:read-syntax my-read-syntax
+
+
+;; Now that we have a parser, let't provide the two functions that a
+;; language reader module needs to define. These are the read and
+;; read-syntax functions.
+(require "parser.rkt")
+
+
+
+;; my-read: input-port -> s-expression
+(define (my-read in)
+ (syntax->datum
+ (my-read-syntax #f in)))
+
+
+
+;; my-read-syntax: any input-port -> syntax-object
+;;
+(define (my-read-syntax src in)
+ ;; Note: we're ignoring our src, but if our parser were a bit nicer,
+ ;; it would also keep track of the src in the resulting syntax
+ ;; objects.
+
+ ;; We also need to return eof once we've exhausted the token stream,
+ ;; so let's do so.
+ (let ([token-stream (get-tokens in)])
+ (cond
+ [(eof-object? (peek token-stream))
+ eof]
+ [else
+ (parse-toplevel token-stream)])))
View
0 lang/semantics.rkt → old-lang/semantics.rkt
File renamed without changes.
View
0 bf/parser.rkt → parser.rkt
File renamed without changes.
View
5 bf/semantics.rkt → semantics.rkt
@@ -44,7 +44,10 @@
(define (read-byte-from-stdin a-state)
(let ([v (state-data a-state)]
[i (state-ptr a-state)])
- (vector-set! v i (read-byte (current-input-port)))))
+ (vector-set! v i (let ([v (read-byte (current-input-port))])
+ (if (eof-object? v)
+ 0
+ v)))))
;; we know how to do loops!

0 comments on commit 67a368e

Please sign in to comment.