Compile-Time objects See Also: S06 The compile-time system builds a 'Program' object. "$program" stringifies to compiled code. Emitted code is an optimized representation of the Runtime. It may be worth developing a working runtime first, and then optimize it into inlined code. Environment - contains the declarations in scope: variables, subroutines - also contains 'want' info. API - unimplemented methods are deferred to the runtime, by emitting a method invocation $object->method( param-list ) ."" (overloaded stringification) - stringifies to source code - this only happens at compile-time # .boxed - creates a boxed object. Example: int.box -> Int # .unboxed - unboxes an object if possible. Example: Int.unbox -> int .WHAT - returns the class as a Class (which stringifies to the class name) .list - returns an object that can be interpolated into a list - sigiled arrays and hashes (@array) can be interpolated; non-sigiled ($array) cannot. Coercions .str .num .int .bool Container operations .bind( $cell ) # XXX .BIND .bind_from # XXX .BIND_FROM - returns this container's cell (as plain source code, not an object ???). Values create read-only cells. # XXX what's the perl6 word for this? .VAR - returns this container's cell $native.bind_from is read-only $native.VAR is read-write .STORE( $value ) .FETCH - returns the cell value .array .hash .scalar - coerce values into containers - does not create a container cell; use .VAR for this - .array and .hash create .VAR for each value .my .our - emit declarations .[] - same as .array .{} - same as .hash - TODO - these operations can be overriden at runtime .[ $value ] - return an lvalue (.bind_from) from an array or list .{ $value } - return an lvalue (.bind_from) from a hash - TODO - these operations can be overriden at runtime Control-flow operations - signature binding, multisub dispatch, subroutine and method inlining - TODO Class-specific operations - some operations can be evaluated at compile-time to optimize the generated code - TODO - these operations can be overriden at runtime - for example: .perl - returns a Str, which contains the object dumped as Perl6 source code XXX .print - returns the code to execute '.print' .true .not .== (encoded to ASCII, as '_61__61_') .eq .elems -------------- Classes See also: S02:Built-in Data Types Native types ... Undefined types ... Immutable types Seq List ... Mutable types Array Hash ... Other types - See S02 Value types, Implementation types, Hierarchical types, Polymorphic types, Parameter types, Generic types, Return types Our higher level objects will likely be Captures, Signatures, and Code/Sub, as well as Types Special Classes These classes are used internally to optimize the implementation, by moving boxing and type-checks to compile-time. (Type)Scalar - a typed Scalar ArrayScalar HashScalar ValueScalar (Type)Seq - a typed Seq ArraySeq - An Array that doesn't contain Lazy components. This can be represented by a Perl5 Array. HashSeq (Type)Expression - a typed expression AnyExpression BoolExpression IntExpression StrExpression ... ArrayExpression HashExpression NamedScalar - '$a' A Scalar called by name NamedArray - '@a' An Array called by name NamedHash - '%h' A Hash called by name (TODO) A Hash that only has Stringified keys. This can be represented by a Perl5 Hash. -------------- Miscellaneus * use ::unicode_sub sub {...} to define methods with non alphanumeric names -------------- Data Structures for Pure-Perl Scalars See also: 'type-example.pl' -- Run time $$a - a Scalar's value - '=' lvalue or rvalue $a - a Scalar's cell - ':=' lvalue or rvalue -- Compile time objects $$a - an Expression object - AnyExpression, IntExpression, ... - or, NamedRValue $a - a NamedScalar object $a = Array... - NamedArray scalar cell ${$a} = \@a - NamedArray list (@a[]) or ArrayScalar ($a[]) ${$a}->[1] - ScalarExpression ${${$a}->[1]} - RValueExpression -- Method examples $a->set(...) - call .set method on $a's cell, with optional type checking $a->bind(...) - call .bind method on $a, with optional type checking $$a->str() - call stringification method on $a's value --- Class Hierarchy ?eval Scalar.isa(Any) Bool::True ?eval Junction.isa(Any) Bool::False Junctions are only quasi-objects, insofar as they represent a linguistic notion rather than an, er, object notion when you say "if A equals 1 or 2" the 1 or 2 is not a real thing. ?eval undef.isa(Any) Bool::True ?eval undef.WHAT ::Scalar is it an ro Scalar? ?eval undef = 1; Error: Can't modify constant item: VUndef apparently so. :) ?eval {42}.WHAT ::Scalar I didn't mean to execute the block ?eval {}.WHAT # Hash? *** evalbot_r14454 is now known as evalbot_r14455 ::Scalar ?eval ({42}.WHAT) ::Block ?eval {42} .WHAT ::Scalar this is one of the suprising results of forcing statement-begining { to start a bare block. my Int $a; my Str $b; $a := $b; # error ??? it should agree with the type of VAR($a) doesn't have to agree with the previous contents. S03: The binding fails if the type of the variable being bound is sufficiently inconsistent with the type of the current declaration. -- Questions $a[10] := 1; @$a = (); # error ??? (1,2,3)[1] # ok - splice a List (1,2,3)[1]=5 # error - List is read-only; doesn't coerce List into Array [1,2,3][1]=5 # ok - Array is read-write - is the type of "0 but True" something like ::(Int|Bool) ? - can multis dispatch on a constant? multi a(1){ "first" }; multi a(2){ "second" }; multi a { "other" };