public
Description: The Nu programming language.
Homepage: http://programming.nu
Clone URL: git://github.com/timburks/nu.git
Search Repo:
Reimplemented (NSObject set:) and (ivar-accessors) in Objective-C.

These changes bring two important Nu features into the Objective-C
core, which makes them easier to use on platforms (iPhone, Linux, etc)
where Nu is built as a static or shared library instead of as a
framework.
timburks (author)
Fri May 16 15:30:27 -0700 2008
commit  b16f4fe293cfebd3b0d6c89428fcb6083cbb7d02
tree    f8c8c869d86762a10068f6527180caa20036be97
parent  ffc4627f0f655662805e055518a95b8dff2fb701
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
...
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
...
828
829
830
831
 
832
...
300
301
302
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
304
305
...
404
405
406
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
407
408
409
...
617
618
619
 
620
621
0
@@ -300,71 +300,6 @@
0
 _nunull()))),
0
 _nunull()))),
0
 _nucell(_nucell(_nusymbol((const char[]){99,108,97,115,115,0}),
0
-_nucell(_nusymbol((const char[]){78,83,79,98,106,101,99,116,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){45,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){105,100,0}),
0
-_nunull()),
0
-_nucell(_nusymbol((const char[]){115,101,116,58,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){105,100,0}),
0
-_nunull()),
0
-_nucell(_nusymbol((const char[]){112,114,111,112,101,114,116,121,76,105,115,116,0}),
0
-_nucell(_nusymbol((const char[]){105,115,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){112,114,111,112,101,114,116,121,76,105,115,116,0}),
0
-_nucell(_nusymbol((const char[]){101,97,99,104,80,97,105,114,58,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){100,111,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){107,101,121,0}),
0
-_nucell(_nusymbol((const char[]){118,97,108,117,101,0}),
0
-_nunull())),
0
-_nucell(_nucell(_nusymbol((const char[]){108,101,116,0}),
0
-_nucell(_nucell(_nucell(_nusymbol((const char[]){108,97,98,101,108,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){105,102,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){97,110,100,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){107,101,121,0}),
0
-_nucell(_nusymbol((const char[]){105,115,75,105,110,100,79,102,67,108,97,115,115,58,0}),
0
-_nucell(_nusymbol((const char[]){78,117,83,121,109,98,111,108,0}),
0
-_nunull()))),
0
-_nucell(_nucell(_nusymbol((const char[]){107,101,121,0}),
0
-_nucell(_nusymbol((const char[]){105,115,76,97,98,101,108,0}),
0
-_nunull())),
0
-_nunull()))),
0
-_nucell(_nucell(_nusymbol((const char[]){116,104,101,110,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){107,101,121,0}),
0
-_nucell(_nusymbol((const char[]){108,97,98,101,108,78,97,109,101,0}),
0
-_nunull())),
0
-_nunull())),
0
-_nucell(_nucell(_nusymbol((const char[]){101,108,115,101,0}),
0
-_nucell(_nusymbol((const char[]){107,101,121,0}),
0
-_nunull())),
0
-_nunull())))),
0
-_nunull())),
0
-_nunull()),
0
-_nucell(_nucell(_nusymbol((const char[]){105,102,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){101,113,0}),
0
-_nucell(_nusymbol((const char[]){108,97,98,101,108,0}),
0
-_nucell(_nustring((const char[]){97,99,116,105,111,110,0}),
0
-_nunull()))),
0
-_nucell(_nucell(_nusymbol((const char[]){116,104,101,110,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){115,101,108,102,0}),
0
-_nucell(_nusymbol((const char[]){115,101,116,65,99,116,105,111,110,58,0}),
0
-_nucell(_nusymbol((const char[]){118,97,108,117,101,0}),
0
-_nunull()))),
0
-_nunull())),
0
-_nucell(_nucell(_nusymbol((const char[]){101,108,115,101,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){115,101,108,102,0}),
0
-_nucell(_nusymbol((const char[]){115,101,116,86,97,108,117,101,58,0}),
0
-_nucell(_nusymbol((const char[]){118,97,108,117,101,0}),
0
-_nucell(_nusymbol((const char[]){102,111,114,75,101,121,58,0}),
0
-_nucell(_nusymbol((const char[]){108,97,98,101,108,0}),
0
-_nunull()))))),
0
-_nunull())),
0
-_nunull())))),
0
-_nunull()))),
0
-_nunull()))),
0
-_nunull()))),
0
-_nucell(_nusymbol((const char[]){115,101,108,102,0}),
0
-_nunull())))))))),
0
-_nunull()))),
0
-_nucell(_nucell(_nusymbol((const char[]){99,108,97,115,115,0}),
0
 _nucell(_nusymbol((const char[]){78,83,77,117,116,97,98,108,101,65,114,114,97,121,0}),
0
 _nucell(_nucell(_nusymbol((const char[]){45,0}),
0
 _nucell(_nucell(_nusymbol((const char[]){118,111,105,100,0}),
0
@@ -469,152 +404,6 @@
0
 _nunull())))))),
0
 _nunull()))),
0
 _nucell(_nucell(_nusymbol((const char[]){103,108,111,98,97,108,0}),
0
-_nucell(_nusymbol((const char[]){105,118,97,114,45,97,99,99,101,115,115,111,114,115,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){109,97,99,114,111,0}),
0
-_nucell(_nusymbol((const char[]){95,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){105,109,101,116,104,111,100,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){105,100,0}),
0
-_nunull()),
0
-_nucell(_nusymbol((const char[]){104,97,110,100,108,101,85,110,107,110,111,119,110,77,101,115,115,97,103,101,58,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){105,100,0}),
0
-_nunull()),
0
-_nucell(_nusymbol((const char[]){109,101,115,115,97,103,101,0}),
0
-_nucell(_nusymbol((const char[]){119,105,116,104,67,111,110,116,101,120,116,58,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){105,100,0}),
0
-_nunull()),
0
-_nucell(_nusymbol((const char[]){99,111,110,116,101,120,116,0}),
0
-_nucell(_nusymbol((const char[]){105,115,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){99,97,115,101,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){109,101,115,115,97,103,101,0}),
0
-_nucell(_nusymbol((const char[]){108,101,110,103,116,104,0}),
0
-_nunull())),
0
-_nucell(_nucell(_nunumberd(1),
0
-_nucell(_nucell(_nusymbol((const char[]){116,114,121,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){115,101,108,102,0}),
0
-_nucell(_nusymbol((const char[]){118,97,108,117,101,70,111,114,73,118,97,114,58,0}),
0
-_nucell(_nucell(_nucell(_nusymbol((const char[]){109,101,115,115,97,103,101,0}),
0
-_nucell(_nusymbol((const char[]){102,105,114,115,116,0}),
0
-_nunull())),
0
-_nucell(_nusymbol((const char[]){115,116,114,105,110,103,86,97,108,117,101,0}),
0
-_nunull())),
0
-_nunull()))),
0
-_nucell(_nucell(_nusymbol((const char[]){99,97,116,99,104,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){101,114,114,111,114,0}),
0
-_nunull()),
0
-_nucell(_nucell(_nusymbol((const char[]){115,117,112,101,114,0}),
0
-_nucell(_nusymbol((const char[]){104,97,110,100,108,101,85,110,107,110,111,119,110,77,101,115,115,97,103,101,58,0}),
0
-_nucell(_nusymbol((const char[]){109,101,115,115,97,103,101,0}),
0
-_nucell(_nusymbol((const char[]){119,105,116,104,67,111,110,116,101,120,116,58,0}),
0
-_nucell(_nusymbol((const char[]){99,111,110,116,101,120,116,0}),
0
-_nunull()))))),
0
-_nunull()))),
0
-_nunull()))),
0
-_nunull())),
0
-_nucell(_nucell(_nunumberd(2),
0
-_nucell(_nucell(_nusymbol((const char[]){105,102,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){101,113,0}),
0
-_nucell(_nucell(_nucell(_nucell(_nusymbol((const char[]){109,101,115,115,97,103,101,0}),
0
-_nucell(_nusymbol((const char[]){102,105,114,115,116,0}),
0
-_nunull())),
0
-_nucell(_nusymbol((const char[]){115,116,114,105,110,103,86,97,108,117,101,0}),
0
-_nunull())),
0
-_nucell(_nusymbol((const char[]){115,117,98,115,116,114,105,110,103,87,105,116,104,82,97,110,103,101,58,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){113,117,111,116,101,0}),
0
-_nucell(_nucell(_nunumberd(0),
0
-_nucell(_nunumberd(3),
0
-_nunull())),
0
-_nunull())),
0
-_nunull()))),
0
-_nucell(_nustring((const char[]){115,101,116,0}),
0
-_nunull()))),
0
-_nucell(_nucell(_nusymbol((const char[]){116,104,101,110,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){116,114,121,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){108,101,116,0}),
0
-_nucell(_nucell(_nucell(_nusymbol((const char[]){102,105,114,115,116,65,114,103,117,109,101,110,116,0}),
0
-_nucell(_nucell(_nucell(_nusymbol((const char[]){109,101,115,115,97,103,101,0}),
0
-_nucell(_nusymbol((const char[]){102,105,114,115,116,0}),
0
-_nunull())),
0
-_nucell(_nusymbol((const char[]){115,116,114,105,110,103,86,97,108,117,101,0}),
0
-_nunull())),
0
-_nunull())),
0
-_nunull()),
0
-_nucell(_nucell(_nusymbol((const char[]){108,101,116,0}),
0
-_nucell(_nucell(_nucell(_nusymbol((const char[]){118,97,114,105,97,98,108,101,78,97,109,101,48,0}),
0
-_nucell(_nucell(_nucell(_nusymbol((const char[]){102,105,114,115,116,65,114,103,117,109,101,110,116,0}),
0
-_nucell(_nusymbol((const char[]){115,117,98,115,116,114,105,110,103,87,105,116,104,82,97,110,103,101,58,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){113,117,111,116,101,0}),
0
-_nucell(_nucell(_nunumberd(3),
0
-_nucell(_nunumberd(1),
0
-_nunull())),
0
-_nunull())),
0
-_nunull()))),
0
-_nucell(_nusymbol((const char[]){108,111,119,101,114,99,97,115,101,83,116,114,105,110,103,0}),
0
-_nunull())),
0
-_nunull())),
0
-_nucell(_nucell(_nusymbol((const char[]){118,97,114,105,97,98,108,101,78,97,109,101,49,0}),
0
-_nucell(_nucell(_nucell(_nusymbol((const char[]){102,105,114,115,116,65,114,103,117,109,101,110,116,0}),
0
-_nucell(_nusymbol((const char[]){115,117,98,115,116,114,105,110,103,87,105,116,104,82,97,110,103,101,58,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){108,105,115,116,0}),
0
-_nucell(_nunumberd(4),
0
-_nucell(_nucell(_nusymbol((const char[]){45,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){102,105,114,115,116,65,114,103,117,109,101,110,116,0}),
0
-_nucell(_nusymbol((const char[]){108,101,110,103,116,104,0}),
0
-_nunull())),
0
-_nucell(_nunumberd(5),
0
-_nunull()))),
0
-_nunull()))),
0
-_nunull()))),
0
-_nunull()),
0
-_nunull())),
0
-_nunull())),
0
-_nucell(_nucell(_nusymbol((const char[]){115,101,108,102,0}),
0
-_nucell(_nusymbol((const char[]){115,101,116,86,97,108,117,101,58,0}),
0
-_nucell(_nucell(_nucell(_nusymbol((const char[]){109,101,115,115,97,103,101,0}),
0
-_nucell(_nusymbol((const char[]){115,101,99,111,110,100,0}),
0
-_nunull())),
0
-_nucell(_nusymbol((const char[]){101,118,97,108,87,105,116,104,67,111,110,116,101,120,116,58,0}),
0
-_nucell(_nusymbol((const char[]){99,111,110,116,101,120,116,0}),
0
-_nunull()))),
0
-_nucell(_nusymbol((const char[]){102,111,114,73,118,97,114,58,0}),
0
-_nucell(_nustring((const char[]){35,123,118,97,114,105,97,98,108,101,78,97,109,101,48,125,35,123,118,97,114,105,97,98,108,101,78,97,109,101,49,125,0}),
0
-_nunull()))))),
0
-_nunull()))),
0
-_nunull()))),
0
-_nucell(_nucell(_nusymbol((const char[]){99,97,116,99,104,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){101,114,114,111,114,0}),
0
-_nunull()),
0
-_nucell(_nucell(_nusymbol((const char[]){115,117,112,101,114,0}),
0
-_nucell(_nusymbol((const char[]){104,97,110,100,108,101,85,110,107,110,111,119,110,77,101,115,115,97,103,101,58,0}),
0
-_nucell(_nusymbol((const char[]){109,101,115,115,97,103,101,0}),
0
-_nucell(_nusymbol((const char[]){119,105,116,104,67,111,110,116,101,120,116,58,0}),
0
-_nucell(_nusymbol((const char[]){99,111,110,116,101,120,116,0}),
0
-_nunull()))))),
0
-_nunull()))),
0
-_nunull()))),
0
-_nunull())),
0
-_nucell(_nucell(_nusymbol((const char[]){101,108,115,101,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){115,117,112,101,114,0}),
0
-_nucell(_nusymbol((const char[]){104,97,110,100,108,101,85,110,107,110,111,119,110,77,101,115,115,97,103,101,58,0}),
0
-_nucell(_nusymbol((const char[]){109,101,115,115,97,103,101,0}),
0
-_nucell(_nusymbol((const char[]){119,105,116,104,67,111,110,116,101,120,116,58,0}),
0
-_nucell(_nusymbol((const char[]){99,111,110,116,101,120,116,0}),
0
-_nunull()))))),
0
-_nunull())),
0
-_nunull())))),
0
-_nunull())),
0
-_nucell(_nucell(_nusymbol((const char[]){101,108,115,101,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){115,117,112,101,114,0}),
0
-_nucell(_nusymbol((const char[]){104,97,110,100,108,101,85,110,107,110,111,119,110,77,101,115,115,97,103,101,58,0}),
0
-_nucell(_nusymbol((const char[]){109,101,115,115,97,103,101,0}),
0
-_nucell(_nusymbol((const char[]){119,105,116,104,67,111,110,116,101,120,116,58,0}),
0
-_nucell(_nusymbol((const char[]){99,111,110,116,101,120,116,0}),
0
-_nunull()))))),
0
-_nunull())),
0
-_nunull()))))),
0
-_nunull())))))))))),
0
-_nunull()))),
0
-_nunull()))),
0
-_nucell(_nucell(_nusymbol((const char[]){103,108,111,98,97,108,0}),
0
 _nucell(_nusymbol((const char[]){112,114,111,116,111,99,111,108,0}),
0
 _nucell(_nucell(_nusymbol((const char[]){109,97,99,114,111,0}),
0
 _nucell(_nusymbol((const char[]){95,0}),
0
@@ -828,6 +617,6 @@
0
 _nunull()))))))))))),
0
 _nunull()))))))))),
0
 _nunull()))),
0
-_nunull())))))))))))))))))))))))))))))))))));
0
+_nunull())))))))))))))))))))))))))))))))))));
0
 }
...
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
...
85
86
87
88
89
 
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 
120
121
122
...
51
52
53
 
 
 
 
 
 
 
 
 
 
 
 
 
54
55
56
57
...
72
73
74
 
 
75
76
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
79
80
81
0
@@ -51,19 +51,6 @@
0
                             (results addObject:filename)))
0
                  ((results allObjects) sortedArrayUsingSelector:"compare:"))))
0
 
0
-(class NSObject
0
-
0
- ;; Concisely set key-value pairs from a property list.
0
- (- (id) set: (id) propertyList is
0
- (propertyList eachPair: (do (key value)
0
- (let ((label (if (and (key isKindOfClass:NuSymbol) (key isLabel))
0
- (then (key labelName))
0
- (else key))))
0
- (if (eq label "action")
0
- (then (self setAction:value))
0
- (else (self setValue:value forKey:label))))))
0
- self))
0
-
0
 (class NSMutableArray
0
      
0
      ;; Concisely add objects to arrays using this method, which is equivalent to a call to addObject:.
0
0
@@ -85,38 +72,10 @@
0
          ;; Convert a list into an NSRange. The list must have at least two elements.
0
          (- (NSRange) rangeValue is (list (self first) (self second)))))
0
 
0
-;; Call this macro in a class declaration to give a class automatic accessors for its instance variables.
0
-;; Watch out for conflicts with other uses of handleUnknownMessage:withContext:.
0
+;; Use this macro to create and extend protocols.
0
 ;; The odd-looking use of the global operator is to define the macro globally.
0
 ;; We just use an "_" for the macro name argument because its local name is unimportant.
0
-(global ivar-accessors
0
- (macro _
0
- (imethod (id) handleUnknownMessage:(id) message withContext:(id) context is
0
- (case (message length)
0
- (1
0
- ;; try to automatically get an ivar
0
- (try
0
- ;; ivar name is the first (only) token of the message
0
- (self valueForIvar:((message first) stringValue))
0
- (catch (error)
0
- (super handleUnknownMessage:message withContext:context))))
0
- (2
0
- ;; try to automatically set an ivar
0
- (if (eq (((message first) stringValue) substringWithRange:'(0 3)) "set")
0
- (then
0
- (try
0
- (let ((firstArgument ((message first) stringValue)))
0
- (let ((variableName0 ((firstArgument substringWithRange:'(3 1)) lowercaseString))
0
- (variableName1 ((firstArgument substringWithRange:
0
- (list 4 (- (firstArgument length) 5))))))
0
- (self setValue:((message second) evalWithContext:context)
0
- forIvar: "#{variableName0}#{variableName1}")))
0
- (catch (error)
0
- (super handleUnknownMessage:message withContext:context))))
0
- (else (super handleUnknownMessage:message withContext:context))))
0
- (else (super handleUnknownMessage:message withContext:context))))))
0
-
0
-;; use this to create and extend protocols
0
+;; It does not work with the latest (more restrictive) ObjC runtimes from Apple.
0
 (global protocol
0
         (macro _
0
              (set __signatureForIdentifier (NuBridgedFunction functionWithName:"signature_for_identifier" signature:"@@@"))
...
1142
1143
1144
 
1145
1146
1147
1148
1149
1150
 
 
1151
1152
1153
...
1142
1143
1144
1145
1146
1147
1148
1149
1150
 
1151
1152
1153
1154
1155
0
@@ -1142,12 +1142,14 @@
0
     }
0
     int argument_count = 0;
0
     while (userdata[argument_count] != 0) argument_count++;
0
+ #if 0
0
     #ifdef DARWIN
0
     const char *methodName = sel_getName(sel);
0
     #else
0
     const char *methodName = sel_get_name(sel);
0
     #endif
0
- //NSLog(@"using libffi to construct handler for method %s with %d arguments and signature %s", methodName, argument_count, signature);
0
+ NSLog(@"using libffi to construct handler for method %s with %d arguments and signature %s", methodName, argument_count, signature);
0
+ #endif
0
     ffi_type **argument_types = (ffi_type **) malloc ((argument_count+1) * sizeof(ffi_type *));
0
     ffi_type *result_type = ffi_type_for_objc_type(userdata[0]+1);
0
     argument_types[0] = ffi_type_for_objc_type("@");
...
238
239
240
241
 
242
243
244
...
249
250
251
 
 
 
 
 
 
 
 
 
 
 
...
238
239
240
 
241
242
243
244
...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
0
@@ -238,7 +238,7 @@
0
     @abstract NSMethodSignature extensions for Nu programming.
0
  */
0
 @interface NSMethodSignature (Nu)
0
-/*! Get the type string for a method signature */
0
+/*! Get the type string for a method signature. */
0
 - (NSString *) typeString;
0
 @end
0
 
0
@@ -249,4 +249,15 @@
0
 + (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
0
 @end
0
 #endif
0
+
0
+/*!
0
+ @class NuAutomaticIvars
0
+ @abstract Include this class to get handleUnknownMessage:withContext: to emulate ivar accessors.
0
+ */
0
+@interface NuAutomaticIvars : NSObject
0
+{
0
+}
0
+/*! Attempt to treat unknown messages as ivar accessors. */
0
+- (id) handleUnknownMessage:(NuCell *) message withContext:(id) context;
0
+@end
...
823
824
825
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
0
@@ -823,4 +823,49 @@
0
     return [[object stringValue] cString];
0
 }
0
 #endif
0
+
0
+
0
+@implementation NuAutomaticIvars
0
+
0
+- (id) handleUnknownMessage:(NuCell *) message withContext:(id) context
0
+{
0
+ int message_length = [message length];
0
+ if (message_length == 1) {
0
+ // try to automatically get an ivar
0
+ @try
0
+ {
0
+ // ivar name is the first (only) token of the message
0
+ return [self valueForIvar:[[message car] stringValue]];
0
+ }
0
+ @catch (id error) {
0
+ return [super handleUnknownMessage:message withContext:context];
0
+ }
0
+ }
0
+ else if (message_length == 2) {
0
+ // try to automatically set an ivar
0
+ if ([[[[message car] stringValue] substringWithRange:NSMakeRange(0,3)] isEqualToString:@"set"]) {
0
+ @try
0
+ {
0
+ id firstArgument = [[message car] stringValue];
0
+ id variableName0 = [[firstArgument substringWithRange:NSMakeRange(3,1)] lowercaseString];
0
+ id variableName1 = [firstArgument substringWithRange:NSMakeRange(4, [firstArgument length] - 5)];
0
+ [self setValue:[[[message cdr] car] evalWithContext:context]
0
+ forIvar:[NSString stringWithFormat:@"%@%@", variableName0, variableName1]];
0
+ return nil;
0
+ }
0
+ @catch (id error) {
0
+ return [super handleUnknownMessage:message withContext:context];
0
+ }
0
+ }
0
+ else {
0
+ return [super handleUnknownMessage:message withContext:context];
0
+ }
0
+ }
0
+ else {
0
+ return [super handleUnknownMessage:message withContext:context];
0
+ }
0
+ return nil;
0
+}
0
+
0
+@end
...
23
24
25
 
26
27
28
...
80
81
82
 
 
 
83
84
...
23
24
25
26
27
28
29
...
81
82
83
84
85
86
87
88
0
@@ -23,6 +23,7 @@
0
 #import <Foundation/Foundation.h>
0
 @class NuBlock;
0
 @class NuClass;
0
+@class NuCell;
0
 
0
 /*!
0
     @category NSObject(Nu)
0
@@ -80,6 +81,9 @@
0
 
0
 /*! Swap a pair of class methods of the underlying class. */
0
 + (BOOL) exchangeClassMethod:(SEL)sel1 withMethod:(SEL)sel2;
0
+
0
+/*! Concisely set key-value pairs from a property list. */
0
+- (id) set:(NuCell *) propertyList;
0
 
0
 @end
...
676
677
678
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
679
...
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
0
@@ -676,5 +676,24 @@
0
     return YES;
0
 }
0
 
0
+// Concisely set key-value pairs from a property list.
0
+- (id) set:(NuCell *) propertyList
0
+{
0
+ id cursor = propertyList;
0
+ while (cursor && (cursor != Nu__null) && ([cursor cdr]) && ([cursor cdr] != Nu__null)) {
0
+ id key = [cursor car];
0
+ id value = [[cursor cdr] car];
0
+ id label = ([key isKindOfClass:[NuSymbol class]] && [key isLabel]) ? [key labelName] : key;
0
+ if ([label isEqualToString:@"action"]) {
0
+ [self setAction:value];
0
+ }
0
+ else {
0
+ [self setValue:value forKey:label];
0
+ }
0
+ cursor = [[cursor cdr] cdr];
0
+ }
0
+ return self;
0
+}
0
+
0
 @end
...
1562
1563
1564
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1565
1566
1567
...
1885
1886
1887
 
1888
1889
1890
...
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
...
1900
1901
1902
1903
1904
1905
1906
0
@@ -1562,6 +1562,21 @@
0
 
0
 @end
0
 
0
+@interface Nu_ivar_accessors_operator : NuOperator {}
0
+@end
0
+
0
+@implementation Nu_ivar_accessors_operator
0
+- (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
0
+{
0
+ NuSymbolTable *symbolTable = [context objectForKey:SYMBOLS_KEY];
0
+ NuClass *classWrapper = [context objectForKey:[symbolTable symbolWithCString:"_class"]];
0
+ Class classToExtend = [classWrapper wrappedClass];
0
+ [classToExtend include:[NuClass classWithClass:[NuAutomaticIvars class]]];
0
+ return Nu__null;
0
+}
0
+
0
+@end
0
+
0
 #if defined(DARWIN) && !defined(IPHONE)
0
 #import <Cocoa/Cocoa.h>
0
 
0
@@ -1885,6 +1900,7 @@
0
     install("cmethod", Nu_cmethod_operator);
0
     install("ivar", Nu_ivar_operator);
0
     install("ivars", Nu_ivars_operator);
0
+ install("ivar-accessors", Nu_ivar_accessors_operator);
0
 
0
     install("call", Nu_call_operator);
0
     install("send", Nu_send_operator);

Comments

    No one has commented yet.