Permalink
Browse files

Removed macro-0 from .nu files and tools. One regression remains for …

…the match functions.
1 parent d2b1f1b commit 54f66349b1f21321d35dd363d692bf49fe871d0b @itfrombit itfrombit committed Jul 4, 2011
Showing with 1,103 additions and 1,122 deletions.
  1. +2 −0 examples/Benwanu/Nukefile
  2. +12 −9 nu/bridgesupport.nu
  3. +9 −8 nu/cocoa.nu
  4. +235 −237 nu/doc.nu
  5. +4 −36 nu/help.nu
  6. +34 −28 nu/match.nu
  7. +22 −59 nu/nu.nu
  8. +132 −118 nu/test.nu
  9. +10 −3 test/test_control.nu
  10. +42 −39 test/test_macros.nu
  11. +1 −0 test/test_macrox.nu
  12. +2 −1 tools/nudoc
  13. +598 −584 tools/nuke
@@ -8,6 +8,8 @@
(set @icon_files (filelist "^resources/.*icns$"))
(set @resources (filelist "^resources/Benwanu Help$"))
+(set @arch '("x86_64"))
+
(@resources addObjectsFromArray:((filelist "^resources/Credits.rtf$") allObjects))
;; application description
View
@@ -21,14 +21,17 @@
functions:(dict))) ;; for each function, remember its signature
(global import
- (macro-0 _
- (NuBridgeSupport importFramework:((margs car) stringValue)
- fromPath:(if (margs cdr) (then (eval ((margs cdr) car))) (else nil))
- intoDictionary:BridgeSupport)))
+ (macro _ (framework *path)
+ `(progn
+ (NuBridgeSupport importFramework:(',framework stringValue)
+ fromPath:(if ,*path (then (car ,*path)) (else nil))
+ intoDictionary:BridgeSupport))))
(global import-system
- (macro-0 _
- (((NSString stringWithShellCommand:"ls /System/Library/Frameworks") lines) each:
- (do (line)
- (set name ((line componentsSeparatedByString:".") 0))
- (eval (cons 'import (list name)))))))
+ (macro _ ()
+ `(progn
+ (((NSString stringWithShellCommand:"ls /System/Library/Frameworks") lines) each:
+ (do (line)
+ (set name ((line componentsSeparatedByString:".") 0))
+ (eval (cons 'import (list name))))))))
+
View
@@ -17,14 +17,14 @@
;; See the License for the specific language governing permissions and
;; limitations under the License.
-(macro-0 bridge
- (set __kind (margs first))
- (set __name (margs second))
- (set __signature (margs third))
- (case __kind
- ('constant (eval (list 'global __name (NuBridgedConstant constantWithName:(__name stringValue) signature:__signature))))
- ('function (eval (list 'global __name (NuBridgedFunction functionWithName:(__name stringValue) signature:__signature))))
- (else (NSLog "invalid argument to bridge: '#{__kind}'"))))
+(macro bridge (kind name signature)
+ (case kind
+ ('constant
+ `(global ,name (NuBridgedConstant constantWithName:(',name stringValue) signature:,signature)))
+ ('function
+ `(global ,name (NuBridgedFunction functionWithName:(',name stringValue) signature:,signature)))
+ (else
+ `(NSLog "invalid argument to bridge: '#{,kind}'"))))
(bridge function NSLog "v@")
(bridge function NSApplicationMain "ii^*")
@@ -86,3 +86,4 @@
(global NSOrderedAscending -1)
(global NSOrderedSame 0)
(global NSOrderedDescending 1)
+
View
472 nu/doc.nu

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -15,42 +15,10 @@
;; See the License for the specific language governing permissions and
;; limitations under the License.
-(if nil ;; This is just here for fun. It shows some alternate ways of building macros.
- (function subst (new old tree)
- (cond ((eq tree old) new)
- ((not tree) tree)
- ((atom tree) tree)
- (else (cons (subst new old (car tree))
- (subst new old (cdr tree))))))
-
- (function meval (pairs code)
- (if pairs
- (then (meval ((pairs cdr) cdr) (subst (pairs second) (pairs first) code)))
- (else (eval code))))
-
- (macro-0 class-help-0
- (meval (list 'className (margs first)
- 'helpText (margs second))
- '(class className
- (- (id) help is helpText))))
-
- (macro-0 class-help-1
- (eval (list 'class (margs first)
- (list '- '(id) 'help 'is (margs second)))))
-
- (macro-0 class-help-2
- (class (unquote (margs first))
- (- (id) help is (unquote (margs second)))))
-
- ; we might prefer this when the parser can handle commas.
- ;(macro-0 class-help-3
- ; (class ,(margs first))
- ; (- (id) help is ,(margs second)))
- )
-
-(macro-0 class-help
- (class (unquote (margs first))
- (- (id) help is (unquote (margs second)))))
+(macro class-help (name text)
+ `(progn
+ (class ,name
+ (- (id) help is ,text))))
;; help text
View
@@ -25,14 +25,10 @@
;; returns
;;
;; (1 2 (3 4))
-(macro-0 match-let1
- (set __pat (margs 0))
- (set __seq (eval (margs 1)))
- (set __body ((margs cdr) cdr))
- (set __bindings (destructure __pat __seq))
+(macro match-let1 (pattern sequence *body)
+ (set __bindings (destructure pattern (eval sequence)))
(check-bindings __bindings)
- (set __result (cons 'let (cons __bindings __body)))
- (eval __result))
+ `(let ,__bindings ,@*body))
;; Assigns variables in a template to values in a structure matching the template.
;; For example
@@ -46,16 +42,13 @@
;; (1 2 (3 4))
;;
;; The name is short for "destructuring set." The semantics are similar to "set."
-(macro-0 match-set
- (set __pat (margs 0))
- (set __seq (eval (margs 1)))
- (set __bindings (destructure __pat __seq))
+(macro match-set (pattern sequence *body)
+ (set __bindings (destructure pattern (eval sequence)))
(check-bindings __bindings)
(set __set-statements
(__bindings map:(do (b)
- (list 'set (b 0) (b 1)))))
- (eval (cons 'progn __set-statements)))
-
+ `(set ,(b 0) ,(b 1)))))
+ `(progn ,@__set-statements))
;; Given a pattern like '(a (b c)) and a sequence like '(1 (2 3)),
;; returns a list of bindings like '((a 1) (b 2) (c 3)).
@@ -241,13 +234,27 @@
;; Matches an object against some patterns with associated expressions.
;; TODO(ijt): boolean conditions for patterns (like "when" in ocaml)
-(macro-0 match
- (set __obj (eval (margs 0)))
- (set __patterns (margs cdr))
- (set __expr (_find-first-match __obj __patterns))
- (if (not __expr)
- (then (throw* "NuMatchException" "No match found")))
- (eval __expr))
+;;(macro-0 match
+;; (set __obj (eval (margs 0)))
+;; (set __patterns (margs cdr))
+;; (set __expr (_find-first-match __obj __patterns))
+;; (if (not __expr)
+;; (then (throw* "NuMatchException" "No match found")))
+;; (eval __expr))
+
+(macro match (object *patterns)
+ ;;(puts "---->")
+ (set __obj (eval object))
+ ;;(print "object: ") (puts object)
+ ;;(print "obj: ") (puts __obj)
+ ;;(print "*patterns: ") (puts *patterns)
+ (set __expr (_find-first-match __obj *patterns))
+ ;;(print "expr: ") (puts __expr)
+ `(progn
+ (if (not __expr)
+ (then (throw* "NuMatchException" "No match found")))
+ (,@__expr))
+ )
;; Variant of (do (args) body) that gives different results depending
;; on the structure of the argument list. For example, here is a
@@ -268,10 +275,9 @@
;; % (f 'x 'y 'z)
;; NuMatchException: No match found
;;
-(macro-0 match-do
- (eval (list 'do '(*args)
- (append (list 'match '*args)
- margs))))
+(macro match-do (*body)
+ `(do (*args)
+ (match *args ,@*body)))
;; Variant of (function name (args) body) that gives different results depending
;; on the structure of the argument list. For example, here is a way to implement
@@ -288,9 +294,8 @@
;; % (slow-map cos '(3.14 0))
;; (-0.9999987317275395 1)
;;
-(macro-0 match-function
- (eval (list 'set (margs 0)
- (cons 'match-do (margs cdr)))))
+(macro match-function (fn *body)
+ `(set ,fn (match-do ,@*body)))
;; Looks for an occurrence of item in the list l.
(function find-atom (item l)
@@ -329,3 +334,4 @@
(+ (id) findAtom:(id) a inSequence:(id) sequence is
(find-atom a sequence)))
+
View
@@ -106,22 +106,21 @@
;; Applies a function to a list of arguments.
;; For example (apply + '(1 2)) returns 3.
(global apply
- (macro-0 _
- (set __f (eval (car margs)))
- (set __args (eval (cdr margs)))
- (eval (cons __f __args))))
+ (macro _ (fn *fnargs)
+ `(eval (cons ,fn ,*fnargs))))
;; Evaluates an expression and raises a NuAssertionFailure if the result is false.
;; For example (assert (eq 1 1)) does nothing but (assert (eq (+ 1 1) 1)) throws
;; an exception.
(global assert
- (macro-0 _
- (set expression (car margs))
- (if (not (eval expression))
- (then (throw ((NSException alloc)
- initWithName:"NuAssertionFailure"
- reason:(expression stringValue)
- userInfo:nil))))))
+ (macro _ (*body)
+ `(progn
+ (set expression ,(car *body))
+ (if (not (eval expression))
+ (then (throw ((NSException alloc)
+ initWithName:"NuAssertionFailure"
+ reason:(expression stringValue)
+ userInfo:nil)))))))
;; Allows mapping a function over multiple lists.
;; For example (map + '(1 2) '(3 4)) returns '(4 6).
@@ -154,13 +153,14 @@
;; For example (assert (eq 1 1)) does nothing but (assert (eq (+ 1 1) 1)) throws
;; an exception.
(global assert
- (macro-0 _
- (set expression (car margs))
- (if (not (eval expression))
- (then (throw ((NSException alloc)
- initWithName:"NuAssertionFailure"
- reason:(expression stringValue)
- userInfo:nil))))))
+ (macro _ (*body)
+ `(progn
+ (set expression ,(car *body))
+ (if (not (eval expression))
+ (then (throw ((NSException alloc)
+ initWithName:"NuAssertionFailure"
+ reason:(expression stringValue)
+ userInfo:nil)))))))
;; Throws an exception.
;; This function is more concise and easier to remember than throw.
@@ -170,9 +170,9 @@
reason:reason
userInfo:nil)))))
(else
- (global assert (macro-0 _ (NSLog "warning: assert is unavailable")))
- (global throw* (macro-0 _ (NSLog "warning: throw* is unavailable")))
- (global throw (macro-0 _ (NSLog "warning: throw is unavailable")))))
+ (global assert (macro _ () (NSLog "warning: assert is unavailable")))
+ (global throw* (macro _ () (NSLog "warning: throw* is unavailable")))
+ (global throw (macro _ () (NSLog "warning: throw is unavailable")))))
;; Returns an array of filenames matching a given pattern.
@@ -217,46 +217,9 @@
;; Convert a list into an NSRange. The list must have at least two elements.
(- (NSRange) rangeValue is (list (self first) (self second)))))
-;; Use this macro to create and extend protocols.
-;; The odd-looking use of the global operator is to define the macro globally.
-;; We just use an "_" for the macro name argument because its local name is unimportant.
-;; It does not work with the latest (more restrictive) ObjC runtimes from Apple.
-(global protocol
- (macro-0 _
- (set __signatureForIdentifier (NuBridgedFunction functionWithName:"signature_for_identifier" signature:"@@@"))
- (function __parse_signature (typeSpecifier)
- (__signatureForIdentifier typeSpecifier (NuSymbolTable sharedSymbolTable)))
-
- (set __name ((margs car) stringValue))
- (unless (set __protocol (Protocol protocolNamed: __name))
- (set __protocol ((Protocol alloc) initWithName: __name)))
- (eval (list 'set (margs car) __protocol))
- (set __rest (margs cdr))
- (while __rest
- (set __method (__rest car))
- (set __returnType (__parse_signature ((__method cdr) car)))
- (set __signature __returnType)
- (__signature appendString:"@:")
- (set __name "#{(((__method cdr) cdr) car)}")
- (set __argumentCursor (((__method cdr) cdr) cdr))
- (while __argumentCursor ;; argument type
- (__signature appendString:(__parse_signature (__argumentCursor car)))
- (set __argumentCursor (__argumentCursor cdr))
- (if __argumentCursor ;; variable name
- (set __argumentCursor (__argumentCursor cdr)))
- (if __argumentCursor ;; selector
- (__name appendString:((__argumentCursor car) stringValue))
- (set __argumentCursor (__argumentCursor cdr))))
- (cond ((or (eq (__method car) '-) (eq (__method car) 'imethod))
- (__protocol addInstanceMethod:__name withSignature:__signature))
- ((or (eq (__method car) '+) (eq (__method car) 'cmethod))
- (__protocol addClassMethod:__name withSignature:__signature))
- (else nil))
- (set __rest (__rest cdr)))))
-
;; profiling macro - experimental
(global profile
- (macro-1 _ (name *body)
+ (macro _ (name *body)
`(progn ((NuProfiler defaultProfiler) start:,name)
(set __result (progn ,@*body))
((NuProfiler defaultProfiler) stop)
Oops, something went wrong.

0 comments on commit 54f6634

Please sign in to comment.