-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathbuiltins.go
More file actions
76 lines (70 loc) · 1.84 KB
/
builtins.go
File metadata and controls
76 lines (70 loc) · 1.84 KB
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
package interpreter
// Copyright (c) 2025-Present Marshall A Burns
// Licensed under the MIT License. See LICENSE for details.
// This file bridges the stdlib builtins into the interpreter package.
// The actual builtin implementations live in pkg/stdlib/builtins.go.
// We also keep getEZTypeName here since it uses the interpreter's type aliases.
import (
"github.com/marshallburns/ez/pkg/object"
"github.com/marshallburns/ez/pkg/stdlib"
)
// builtins maps function names to their implementations.
// The actual implementations are in pkg/stdlib/.
var builtins map[string]*object.Builtin
func init() {
// Get all builtins from the stdlib package
builtins = stdlib.GetAllBuiltins()
}
// getEZTypeName returns the EZ language type name for an object
// For integers, returns the declared type (e.g., "u64", "i32") instead of generic "INTEGER"
// For arrays and maps, returns the typed format (e.g., "[string]", "map[string:int]")
func getEZTypeName(obj Object) string {
switch v := obj.(type) {
case *Integer:
return v.GetDeclaredType()
case *Float:
return "float"
case *String:
return "string"
case *Boolean:
return "bool"
case *Char:
return "char"
case *Byte:
return "byte"
case *Array:
if v.ElementType != "" {
return "[" + v.ElementType + "]"
}
return "array"
case *Map:
if v.KeyType != "" && v.ValueType != "" {
return "map[" + v.KeyType + ":" + v.ValueType + "]"
}
return "map"
case *Struct:
if v.TypeName != "" {
return v.TypeName
}
return "struct"
case *EnumValue:
return v.EnumType
case *Nil:
return "nil"
case *Function:
return "function"
case *Range:
return "Range<int>"
case *FileHandle:
return "File"
case *Database:
return "Database"
case *Reference:
if inner, ok := v.Deref(); ok {
return "Ref<" + getEZTypeName(inner) + ">"
}
return "Ref"
default:
return string(obj.Type())
}
}