File tree Expand file tree Collapse file tree 5 files changed +52
-7
lines changed
main/scala/hkmc2/semantics Expand file tree Collapse file tree 5 files changed +52
-7
lines changed Original file line number Diff line number Diff line change @@ -64,14 +64,20 @@ object Elaborator:
64
64
def getBuiltin (nme : Str ): Opt [Ctx .Elem ] =
65
65
parent.filter(_.parent.nonEmpty).fold(env.get(nme))(_.getBuiltin(nme))
66
66
object Builtins :
67
- private def assumeBuiltinCls (nme : Str ): ClassSymbol =
67
+ private def assumeBuiltin (nme : Str ): Symbol =
68
68
getBuiltin(nme)
69
- .getOrElse(throw new NoSuchElementException (s " builtin $nme ${ env.keySet} $parent " ))
69
+ .getOrElse(throw new NoSuchElementException (s " builtin $nme not in ${parent.map(_. env.keySet)} " ))
70
70
.symbol.getOrElse(throw new NoSuchElementException (s " builtin symbol $nme" ))
71
- .asCls.getOrElse(throw new NoSuchElementException (s " builtin class symbol $nme" ))
71
+ private def assumeBuiltinCls (nme : Str ): ClassSymbol =
72
+ assumeBuiltin(nme).asCls.getOrElse(throw new NoSuchElementException (
73
+ s " builtin class symbol $nme" ))
74
+ private def assumeBuiltinMod (nme : Str ): ModuleSymbol =
75
+ assumeBuiltin(nme).asMod.getOrElse(throw new NoSuchElementException (
76
+ s " builtin module symbol $nme" ))
72
77
val Int = assumeBuiltinCls(" Int" )
73
78
val Num = assumeBuiltinCls(" Num" )
74
79
val Str = assumeBuiltinCls(" Str" )
80
+ val Predef = assumeBuiltinMod(" Predef" )
75
81
76
82
object Ctx :
77
83
abstract class Elem :
Original file line number Diff line number Diff line change @@ -25,6 +25,12 @@ const Predef$class = class Predef {
25
25
} ;
26
26
this . TraceLogger = new TraceLogger$class ;
27
27
this . TraceLogger . class = TraceLogger$class ;
28
+ this . Test = class Test {
29
+ constructor ( ) {
30
+ this . y = 1 ;
31
+ }
32
+ toString ( ) { return "Test" ; }
33
+ } ;
28
34
}
29
35
id ( x ) {
30
36
return x ;
@@ -39,9 +45,14 @@ const Predef$class = class Predef {
39
45
pipe ( x2 , f ) {
40
46
return f ( x2 ) ;
41
47
}
42
- call ( receiver , f1 ) {
43
- return ( arg ) => {
44
- return f1 . call ( receiver , arg ) ;
48
+ apply ( receiver , f1 ) {
49
+ return ( ...args ) => {
50
+ return f1 ( receiver , ...args ) ;
51
+ } ;
52
+ }
53
+ call ( receiver1 , f2 ) {
54
+ return ( ...args ) => {
55
+ return f2 . call ( receiver1 , ...args ) ;
45
56
} ;
46
57
}
47
58
print ( x3 ) {
Original file line number Diff line number Diff line change @@ -7,7 +7,9 @@ fun not(x) = x is false
7
7
8
8
fun (|>) pipe(x, f) = f(x)
9
9
10
- fun (|>.) call(receiver, f)(arg) = f.call(receiver, arg)
10
+ fun (.) apply(receiver, f)(...args) = f(receiver, ...args)
11
+
12
+ fun (|>.) call(receiver, f)(...args) = f.call(receiver, ...args)
11
13
12
14
fun print(x) =
13
15
console.log(String(x))
@@ -37,3 +39,7 @@ module TraceLogger with
37
39
prev
38
40
fun resetIndent(n) = set indentLvl = n
39
41
fun log(msg) = console.log("| ".repeat(indentLvl) + msg)
42
+
43
+ class Test with
44
+ val y = 1
45
+
Original file line number Diff line number Diff line change
1
+ :js
2
+
3
+
4
+ Test === Predef.Test
5
+ //│ = true
6
+
7
+ Predef.Test === globalThis.Predef.Test
8
+ //│ = true
9
+
10
+ (new Predef.Test).y
11
+ //│ = 1
12
+
13
+ :re
14
+ (new Predef.Test).x
15
+ //│ ═══[RUNTIME ERROR] Error: Access to required field 'x' yielded 'undefined'
16
+
17
+
Original file line number Diff line number Diff line change @@ -20,6 +20,11 @@ declare val process
20
20
declare val fs
21
21
22
22
23
+ declare module Predef with
24
+ class Test with
25
+ val x = 0
26
+
27
+
23
28
// TODO: rm
24
29
25
30
declare fun log: (Any) -> ()
You can’t perform that action at this time.
0 commit comments