Minimal (?) protype-based language.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 

261 wiersze
7.5 KiB

nil 42 3.140000 string Symbol newline
Object => <Object>
Lambda => <Lambda>
Closure => <Closure>
o = Object.new() => <<Object>>
o = Object.new(foo:42, bar: 666) => <<Object>>
| bar: 666
| foo: 42
o.foo => 42
Point.new() => <<Point>>
Point.new(x: 3, y: 4) => <<Point>>
| x: 3
| y: 4
twice 21 is 42
double => <<Closure>>
| environment: nil
| function: <<Lambda>>
| | body: <<Object>>
| | | 0: <<Binop>>
| | | | operation: 13
| | | | 0: <<GetVar>>
| | | | | name: x
| | | | 1: <<GetVar>>
| | | | | name: x
| | parameters: <<Object>>
| | | 0: x
Point.new(x:3, y:4).magnitude() => 5.000000
<<?>>
| self: nil =>
| n: 39
| self: nil
| 0: 40
40
<<?>>
| self: nil =>
| n: 40
| self: nil
| 0: 40
41
<<?>>
| self: nil =>
| n: 41
| self: nil
| 0: 40
42
<<?>>
| self: nil =>
| n: 42
| self: nil
| 0: 40
43
<Object>
| __codeon__: <primitive Object.codeOn>
| __eval__: <primitive Object.__eval__>
| __name__: Object
| allKeys: <primitive Object.allKeys>
| findKey: <primitive Object.findKey>
| includes: <primitive Object.includes>
| keys: <primitive Object.keys>
| length: <primitive Object.length>
| new: <primitive Object.new>
| pop: <primitive Object.pop>
| push: <primitive Object.push>
| reversed: <primitive Object.reversed>
| sorted: <primitive Object.sorted>
nil no
1 yes
hello yes
15
1973
42 42 42 42
ok
ok
42
----
MyType.__eval__() invoked
42
<<Closure>>
====
42
hello
nil
<Undefined>
<Object>
nil
[KEY: __delegate__
KEY: x
KEY: y
]
Symbol
<Symbol>
<Object>
nil
POINT <Point>
P <<Object>>
P <<Point>>
Q <<Point>>
P.mag 13.000000
<<Object>>
| bar: 666
| foo: 42
| 0: 1
| 1: <<Object>>
| | 0: 2
| | 1: 3
| | 2: 42
[KEY: __delegate__
KEY: bar
KEY: foo
]
5
7
0
1
2
0
1
0: a
2
0: a
1: b
3
0: a
1: b
2: c
12
0: 104
1: 101
2: 108
3: 108
4: 111
5: 44
6: 32
7: 119
8: 111
9: 114
10: 108
11: 100
hello, world
hallo, world
hally, world
hally, wirld
READ = f() { print(__env__()) }
f();
0 30 t
<<Stream>>
f 102 ( 40 ) 41 32 { 123 32 p 112 r 114 i 105 n 110 t 116 ( 40 _ 95 _ 95 e 101 n 110 v 118 _ 95 _ 95 ( 40 ) 41 ) 41 32 } 125
10 f 102 ( 40 ) 41 ; 59
10
42
42
42
42
MACRO table <<Object>>
| assert: <<Closure>>
| | environment: nil
| | function: <<Lambda>>
| | | body: <<Object>>
| | | | 0: <<Unyop>>
| | | | | operation: 3
| | | | | 0: <<Block>>
| | | | | | body: <<Object>>
| | | | | | | 0: <<If>>
| | | | | | | | alternate: nil
| | | | | | | | condition: <<Unyop>>
| | | | | | | | | operation: 0
| | | | | | | | | 0: <<Call>>
| | | | | | | | | | arguments: <<Object>>
| | | | | | | | | | | 0: <<Unyop>>
| | | | | | | | | | | | operation: 4
| | | | | | | | | | | | 0: <<GetVar>>
| | | | | | | | | | | | | name: x
| | | | | | | | | | function: <<GetVar>>
| | | | | | | | | | | name: eval
| | | | | | | | consequent: <<Block>>
| | | | | | | | | body: <<Object>>
| | | | | | | | | | 0: <<Call>>
| | | | | | | | | | | arguments: <<Object>>
| | | | | | | | | | | | 0: "\nassertion failed: "
| | | | | | | | | | | | 1: <<Unyop>>
| | | | | | | | | | | | | operation: 4
| | | | | | | | | | | | | 0: <<Call>>
| | | | | | | | | | | | | | arguments: <<Object>>
| | | | | | | | | | | | | | | 0: <<GetVar>>
| | | | | | | | | | | | | | | | name: x
| | | | | | | | | | | | | | function: <<GetVar>>
| | | | | | | | | | | | | | | name: codeString
| | | | | | | | | | | | 2: "\n"
| | | | | | | | | | | function: <<GetVar>>
| | | | | | | | | | | | name: print
| | | | | | | | | | 1: <<Call>>
| | | | | | | | | | | arguments: <<Object>>
| | | | | | | | | | | | 0: 1
| | | | | | | | | | | function: <<GetVar>>
| | | | | | | | | | | | name: exit
| | | parameters: <<Object>>
| | | | 0: x
| test: <<Closure>>
| | environment: nil
| | function: <<Lambda>>
| | | body: <<Object>>
| | | | 0: <<Call>>
| | | | | arguments: <<Object>>
| | | | | | 0: "MACRO EVAL test with "
| | | | | | 1: <<GetVar>>
| | | | | | | name: x
| | | | | | 2: " and "
| | | | | | 3: <<GetVar>>
| | | | | | | name: y
| | | | | | 4: "\n"
| | | | | function: <<GetVar>>
| | | | | | name: print
| | | | 1: <<Unyop>>
| | | | | operation: 3
| | | | | 0: <<Block>>
| | | | | | body: <<Object>>
| | | | | | | 0: <<Call>>
| | | | | | | | arguments: <<Object>>
| | | | | | | | | 0: "REPLACEMENT "
| | | | | | | | | 1: <<Unyop>>
| | | | | | | | | | operation: 4
| | | | | | | | | | 0: <<GetVar>>
| | | | | | | | | | | name: x
| | | | | | | | | 2: "\n"
| | | | | | | | function: <<GetVar>>
| | | | | | | | | name: print
| | | | | | | 1: <<Unyop>>
| | | | | | | | operation: 4
| | | | | | | | 0: <<GetVar>>
| | | | | | | | | name: y
| | | parameters: <<Object>>
| | | | 0: x
| | | | 1: y
define testfun
MACRO EVAL test with 1 and 2
MACRO EVAL test with three and four
call testfun
REPLACEMENT 1
REPLACEMENT three
MakeSeven.__eval__ invoked
AST eval => 42
0 1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 8 9
65 66 67 68 69
1 two 3 four
*: type error: illegal operand types: <Integer> and <Undefined>
13: n * factorial(n - 1)
12: if (n < 2) nil else n * factorial(n - 1)
11: factorial(n - 1)
10: n * factorial(n - 1)
9: if (n < 2) nil else n * factorial(n - 1)
8: factorial(n - 1)
7: n * factorial(n - 1)
6: if (n < 2) nil else n * factorial(n - 1)
5: factorial(n - 1)
4: n * factorial(n - 1)
3: if (n < 2) nil else n * factorial(n - 1)
2: factorial(5)
1: { factorial(5) }
0: try { factorial(5) } catch (e) { { if (!eval(e.__function__ == "*")) { print("\nassertion failed: ", "e.__function__ == \"*\"", "\n"); exit(1) } }; { if (!eval(e.__kind__ == "type error")) { print("\nassertion failed: ", "e.__kind__ == \"type error\"", "\n"); exit(1) } }; { if (!eval(e.__message__ == "illegal operand types")) { print("\nassertion failed: ", "e.__message__ == \"illegal operand types\"", "\n"); exit(1) } }; { if (!eval(e.operand1 == 2)) { print("\nassertion failed: ", "e.operand1 == 2", "\n"); exit(1) } }; { if (!eval(e.operand2 == nil)) { print("\nassertion failed: ", "e.operand2 == nil", "\n"); exit(1) } }; print(e.__function__, ": ", e.__kind__, ": ", e.__message__, ": ", typeName(e.operand1), " and ", typeName(e.operand2), "\n"); backtrace(e) }