/
README-perlito5-js
181 lines (122 loc) · 4.47 KB
/
README-perlito5-js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
* Perlito5 compiler globals
- context: system-wide; shared by all modules
$Perlito5::CORE_PROTO = { 'CORE::join' => '$@' }
- hashref with subroutine-full-name to prototype mappings in the CORE package only
$Perlito5::PROTO = { 'main::mysub' => undef }
- hashref with subroutine-full-name to prototype mappings
- context: module-wide
$Perlito5::PKG_NAME = "main"
- the current package name (unescaped string)
- context: subroutine-wide
$Perlito5::THROW = 1
- boolean value; tracks if the current subroutine needs to catch a javascript "throw" as a return-value
- context: lexical block
$Perlito5::VAR = [ { '$_' => { decl => 'our', namespace => 'main' } ]
- arrayref-of-hashes with variable-short-names to (declaration type, namespace) mappings
* Perlito5 Javascript Data model Overview
method call
- lookup the method in the _class_ attribute; follow the class hierarchy through @ISA until the UNIVERSAL base class.
- do a native call on the method.
- the argument list is the named array "List__" (that is, "@_").
- additional arguments can be used to pass out-of-band data, such as: caller(), wantarray()
- the invocant is the first argument. "this" is not used.
subroutine call
- lookup the subroutine in the current namespace; follow the hierarchy until the CORE base class.
- do a native method call.
- the argument list is the named array "List__" (that is, "@_").
- additional arguments can be used to pass out-of-band data, such as: caller(), wantarray()
- "this" is not used.
Hash
- native {}
Array
- native []
Scalar
- native value
HashRef
- native {} wrapped in a "HashRef" object
ArrayRef
- native [] wrapped in a "ArrayRef" object
ScalarRef
- native value wrapped in a "ScalarRef" object
CodeRef
- native value
Object
- one of the reference types, with a _class_ attribute
Class
- classes are stored in the CLASS global hash
- the _class_ attribute points to the class itself
- classes inherit from UNIVERSAL
Namespace
- namespaces are stored in the p5pkg global hash
- current namespace object is in the PKG variable
- Namespace inherits from from CORE::GLOBAL, which inherits from CORE
- Namespace is a copy of the Class, but with a different inheritance
- Namespace and Class are updated in parallel, both when a sub is declared or when using typeglob assignment
Calling context ("wantarray", caller)
- TODO
- these are the possible compile-time contexts:
'scalar'
'list'
'void'
'runtime' (unknown)
'str'
'bool'
'num'
- at run-time the contexts are in wantarray ("p5want" variable):
1
0
undef
Alias
- TODO
- using String/Boolean/Number (boxed types) as SCALARs doesn't seem to work
List (eg. subroutine return value)
- native []
eval string
- the compiler gets the current namespace as an argument
- javascript eval() happens at the current runtime lexical context
eval block
- ...
do block
- ...
AUTOLOAD
- TODO
my
- ...
local
- ...
our
- ...
* Javascript resources
https://github.com/eriwen/javascript-stacktrace
- how to get a stacktrace in browsers
https://github.com/audreyt/pugs/tree/master/perl5/PIL2JS
- Pugs Perl6 in javascript
* Regex
- modifiers: g i m
- slashes must be escaped
- From http://www.regular-expressions.info/javascript.html
No \A or \Z anchors to match the start or end of the string. Use a caret or dollar instead.
Lookbehind is not supported at all. Lookahead is fully supported.
No atomic grouping or possessive quantifiers
No Unicode support, except for matching single characters with
No named capturing groups. Use numbered capturing groups instead.
No mode modifiers to set matching options within the regular expression.
No conditionals.
No regular expression comments.
* Cell-based aliasing (TODO)
- slow
- allows aliasing (rw parameters to functions)
- allows "tie", because collection access is done through methods
- simplifies autovivification
- allows lvalue subroutines, such as chop(), chomp(), keys(), pos(), substr(), undef()
- allows "our"
- examples:
v = new Cell();
v.set(5);
f(v); // f gets a copy of the cell; v.set() inside f() modifies the original variable.
1 + v; // calls v.valueOf()
x = v; // alias (copies the cell); v.set() modifies x.valueOf()
x.set( v.valueOf() ); // copies the value (doesn't alias)
h.lookup("x"); // looks up h["x"] for a cell; autovivifies if needed
v.lookup("x"); // error if the cell in v contains something else than undef or an arrayref
- see mp6_Scalar class in src6/lib/Perlito/Python/Runtime.py