@@ -492,80 +492,6 @@ class PickleObject {
492
492
}
493
493
}
494
494
495
- /**
496
- * @param {string | number | BigInt | PickleBuiltinFunctionCallback } it
497
- * @returns {PickleObject }
498
- */
499
- function toPickle ( it ) {
500
- switch ( typeof it ) {
501
- case "string" :
502
- return new PickleString ( it ) ;
503
- case "number" :
504
- return new PickleFloat ( it ) ;
505
- case "function" :
506
- return new PickleBuiltinFunction ( it ) ;
507
- default :
508
- if ( it instanceof BigInt ) return new PickleInteger ( it ) ;
509
- }
510
- throw new PickleError ( `can't convert ${ typeof it } ` ) ;
511
- }
512
-
513
- /**
514
- * Create an object with the specified properties.
515
- * @param {...PickleObject } prototypes
516
- * @param {{properties: string | number | BigInt | function, operators: [PickleOperator, string | number | BigInt | function][]} } data
517
- */
518
- function newPickleObject ( ) {
519
- /**
520
- * @type {PickleObject[] }
521
10000
- */
522
- var prototypes = [ ] . slice . call ( arguments ) ;
523
- /**
524
- * @type {{properties: string | number | BigInt | function, operators: [PickleOperator, string | number | BigInt | function][]} }
525
- */
526
- var data = prototypes . pop ( ) ;
527
- var o = new PickleObject ( ...prototypes ) ;
528
- if ( data . properties )
529
- for ( var pname of Object . getOwnPropertyNames ( data . properties ) ) {
530
- o . properties . set ( pname , toPickle ( data . properties [ pname ] ) ) ;
531
- }
532
- if ( data . operators )
533
- for ( var [ op , payload ] of data . operators ) {
534
- o . operators . set ( op , toPickle ( payload ) ) ;
535
- }
536
- return o ;
537
- }
538
-
539
- const PickleObjectPrototype = newPickleObject ( {
540
- operators : [
541
- [ new PickleOperator ( "." , "left" , 100 ) , function ( args , scope ) {
542
- var x , prop = args . get ( 0 ) ;
543
- for ( var p of this . getMRO ( ) )
544
- if ( ( x = p . properties . find ( prop ) ) )
545
- return new PickleBoundProperty ( this , x ) ;
546
- throw new PickleError ( `no ${ p . sym } in ${ this . typeName } object` ) ;
547
- } ]
548
- ]
549
- } ) ;
550
-
551
- const PickleSymbolPrototype = newPickleObject ( PickleObjectPrototype , {
552
- operators : [
553
- [ new PickleOperator ( "$" , "prefix" , 100 ) , function ( args , scope ) {
554
- var x ;
555
- for ( var s of this . getMRO ( ) )
556
- if ( s instanceof PickleScope && ( x = s . bindings . find ( this . sym ) ) )
557
- return x ;
558
- throw new PickleError ( `undefined variable ${ this . sym } ` ) ;
559
- } ] ,
560
- [ new PickleOperator ( "=" , "left" , - 1 ) , function ( args , scope ) {
561
- return new PicklePropertySetter ( this , args . get ( 0 ) ) ;
562
- } ] ,
563
- [ new PickleOperator ( "==" , "left" , 2 ) , function ( args , scope ) {
564
- return new PickleBoolean ( this === args . get ( 0 ) ) ;
565
- } ] ,
566
- ]
567
- } ) ;
568
-
569
495
class PickleSymbol extends PickleObject {
570
496
static typeName = "symbol" ;
571
497
/**
@@ -589,21 +515,6 @@ class PickleSymbol extends PickleObject {
589
515
}
590
516
}
591
517
592
- const PickleStringPrototype = newPickleObject ( PickleObjectPrototype , {
593
- operators : [
594
- [ new PickleOperator ( "+" , "left" , 100 ) , function ( args , scope ) {
595
- var other = args . get ( 0 ) ;
596
- if ( ! ( other instanceof PickleString ) ) throw new PickleError ( `can't add string to ${ other . typeName } ` ) ;
597
- return new PickleString ( this . str + other . str ) ;
598
- } ]
599
- [ new PickleOperator ( "*" , "left" , 100 ) , function ( args , scope ) {
600
- var other = args . get ( 0 ) ;
601
- if ( ! ( other instanceof PickleScalar ) ) throw new PickleError ( `can't repeat string by ${ other . typeName } ` ) ;
602
- return new PickleString ( this . str . repeat ( other . num ) ) ;
603
- } ]
604
- ]
605
- } ) ;
606
-
607
518
class PickleString extends PickleObject {
608
519
static typeName = "string" ;
609
520
/**
@@ -910,6 +821,97 @@ class PicklePropertySetter extends PickleInternalObject {
910
821
}
911
822
}
912
823
824
+ /**
825
+ * @param {string | number | BigInt | PickleBuiltinFunctionCallback } it
826
+ * @returns {PickleObject }
827
+ */
828
+ function toPickle ( it ) {
829
+ switch ( typeof it ) {
830
+ case "string" :
831
+ return new PickleString ( it ) ;
832
+ case "number" :
833
+ return new PickleFloat ( it ) ;
834
+ case "function" :
835
+ return new PickleBuiltinFunction ( it ) ;
836
+ case "boolean" :
837
+ return new PickleBoolean ( it ) ;
838
+ default :
839
+ if ( it instanceof BigInt ) return new PickleInteger ( it ) ;
840
+ }
841
+ throw new PickleError ( `can't convert ${ typeof it } ` ) ;
842
+ }
843
+
844
+ /**
845
+ * Create an object with the specified properties.
846
+ * @param {...PickleObject } prototypes
847
+ * @param {{properties: string | number | BigInt | function, operators: [PickleOperator, string | number | BigInt | function][]} } data
848
+ */
849
+ function newPickleObject ( ) {
850
+ /**
851
+ * @type {PickleObject[] }
852
+ */
853
+ var prototypes = [ ] . slice . call ( arguments ) ;
854
+ /**
855
+ * @type {{properties: string | number | BigInt | function, operators: [PickleOperator, string | number | BigInt | function][]} }
856
+ */
857
+ var data = prototypes . pop ( ) ;
858
+ var o = new PickleObject ( ...prototypes ) ;
859
+ if ( data . properties )
860
+ for ( var pname of Object . getOwnPropertyNames ( data . properties ) ) {
861
+ o . properties . set ( pname , toPickle ( data . properties [ pname ] ) ) ;
862
+ }
863
+ if ( data . operators )
864
+ for ( var [ op , payload ] of data . operators ) {
865
+ o . operators . set ( op , toPickle ( payload ) ) ;
866
+ }
867
+ return o ;
868
+ }
869
+
870
+ const PickleObjectPrototype = newPickleObject ( {
871
+ operators : [
872
+ [ new PickleOperator ( "." , "left" , 100 ) , function ( args , scope ) {
873
+ var x , prop = args . get ( 0 ) ;
874
+ for ( var p of this . getMRO ( ) )
875
+ if ( ( x = p . properties . find ( prop ) ) )
876
+ return new PickleBoundProperty ( this , x ) ;
877
+ throw new PickleError ( `no ${ p . sym } in ${ this . typeName } object` ) ;
878
+ } ]
879
+ ]
880
+ } ) ;
881
+
882
+ const PickleSymbolPrototype = newPickleObject ( PickleObjectPrototype , {
883
+ operators : [
884
+ [ new PickleOperator ( "$" , "prefix" , 100 ) , function ( args , scope ) {
885
+ var x ;
886
+ for ( var s of this . getMRO ( ) )
887
+ if ( s instanceof PickleScope && ( x = s . bindings . find ( this . sym ) ) )
888
+ return x ;
889
+ throw new PickleError ( `undefined variable ${ this . sym } ` ) ;
890
+ } ] ,
891
+ [ new PickleOperator ( "=" , "left" , - 1 ) , function ( args , scope ) {
892
+ return new PicklePropertySetter ( this , args . get ( 0 ) ) ;
893
+ } ] ,
894
+ [ new PickleOperator ( "==" , "left" , 2 ) , function ( args , scope ) {
895
+ return new PickleBoolean ( this === args . get ( 0 ) ) ;
896
+ } ] ,
897
+ ]
898
+ } ) ;
899
+
900
+ const PickleStringPrototype = newPickleObject ( PickleObjectPrototype , {
901
+ operators : [
902
+ [ new PickleOperator ( "+" , "left" , 100 ) , function ( args , scope ) {
903
+ var other = args . get ( 0 ) ;
904
+ if ( ! ( other instanceof PickleString ) ) throw new PickleError ( `can't add string to ${ other . typeName } ` ) ;
905
+ return new PickleString ( this . str + other . str ) ;
906
+ } ]
907
+ [ new PickleOperator ( "*" , "left" , 100 ) , function ( args , scope ) {
908
+ var other = args . get ( 0 ) ;
909
+ if ( ! ( other instanceof PickleScalar ) ) throw new PickleError ( `can't repeat string by ${ other . typeName } ` ) ;
612B
910
+ return new PickleString ( this . str . repeat ( other . num ) ) ;
911
+ } ]
912
+ ]
913
+ } ) ;
914
+
913
915
/**
914
916
* An object that parses Pickle code into an abstract syntax tree.
915
917
*/
0 commit comments