@effekt-lang/effekt 0.72.0 → 0.74.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/effekt CHANGED
Binary file
@@ -152,6 +152,9 @@ extern def infixPlusPlus(s1: String, s2: String) at {}: String =
152
152
  ret %Pos %spz
153
153
  """
154
154
 
155
+ /// Beware that this function is backend-dependent.
156
+ /// If you want to get the number of bytes that a string would take up in a UTF-8 encoding,
157
+ /// use `string::utf8ByteLength` instead.
155
158
  extern def length(str: String) at {}: Int =
156
159
  js "${str}.length"
157
160
  chez "(string-length ${str})"
@@ -808,6 +811,7 @@ namespace C {
808
811
  extern type Double = llvm "double"
809
812
  extern type Float = llvm "float"
810
813
  extern type Ptr = llvm "ptr"
814
+ extern type Obj = llvm "%CObject"
811
815
  extern type Void = llvm "void"
812
816
 
813
817
  // Type conversion: effekt -> C
@@ -204,6 +204,23 @@ def lastIndexOf(str: String, sub: String, from: Int): Option[Int] = {
204
204
  go(from)
205
205
  }
206
206
 
207
+ namespace internal {
208
+ def utf8ByteLength(str: String): Int = stream::sum {
209
+ for {str.each} { (c: Char) =>
210
+ do emit(c.utf8ByteCount)
211
+ }
212
+ }
213
+ }
214
+
215
+ /// Returns the number of bytes that the given `str` would take up in a UTF-8 encoding.
216
+ extern def utf8ByteLength(str: String) at {io, global}: Int =
217
+ jsNode "Buffer.byteLength(${str}, 'utf8')"
218
+ llvm """
219
+ %x = call %Int @c_bytearray_size(%Pos ${str})
220
+ ret %Int %x
221
+ """ // via bytearray::fromString(str).length
222
+ default { internal::utf8ByteLength(str) }
223
+
207
224
  // TODO more efficient (native) implementations could be integrated as follows
208
225
 
209
226
  // extern def indexOf(str: String, sub: String) at {}: Option[Int] =
@@ -23,6 +23,9 @@
23
23
  ; +-----------------+--------+-------------+
24
24
  %Object = type ptr
25
25
 
26
+ ; C-visible managed objects point at the payload, not at the header.
27
+ %CObject = type ptr
28
+
26
29
 
27
30
  ; A Frame has the following layout
28
31
  ;
@@ -219,6 +222,41 @@ define void @eraseNegative(%Neg %val) alwaysinline {
219
222
  }
220
223
 
221
224
 
225
+ ; User-facing C-helpers for GC
226
+
227
+ define %CObject @effekt_alloc(%Eraser %eraser, i64 %size) {
228
+ %object = call %Object @newObject(%Eraser %eraser, i64 %size)
229
+ %environment = call %Environment @objectEnvironment(%Object %object)
230
+ ret %CObject %environment
231
+ }
232
+
233
+ define void @effekt_share(%CObject %object) {
234
+ %isNull = icmp eq %CObject %object, null
235
+ br i1 %isNull, label %done, label %next
236
+
237
+ next:
238
+ %header = getelementptr %Header, ptr %object, i64 -1
239
+ call void @shareObject(%Object %header)
240
+ br label %done
241
+
242
+ done:
243
+ ret void
244
+ }
245
+
246
+ define void @effekt_erase(%CObject %object) {
247
+ %isNull = icmp eq %CObject %object, null
248
+ br i1 %isNull, label %done, label %next
249
+
250
+ next:
251
+ %header = getelementptr %Header, ptr %object, i64 -1
252
+ call void @eraseObject(%Object %header)
253
+ br label %done
254
+
255
+ done:
256
+ ret void
257
+ }
258
+
259
+
222
260
  ; Arena management
223
261
 
224
262
  define private %Stack @getStack(%Prompt %prompt) {
@@ -823,6 +861,37 @@ define ccc ptr @coercePosPtr(%Pos %input) {
823
861
  ret ptr %d
824
862
  }
825
863
 
864
+ define ccc %Pos @coerceObjPos(%CObject %input) {
865
+ entry:
866
+ %isNull = icmp eq %CObject %input, null
867
+ br i1 %isNull, label %done, label %next
868
+
869
+ next:
870
+ %header = getelementptr %Header, ptr %input, i64 -1
871
+ br label %done
872
+
873
+ done:
874
+ %object = phi %Object [ null, %entry ], [ %header, %next ]
875
+ %boxed1 = insertvalue %Pos zeroinitializer, i64 0, 0
876
+ %boxed2 = insertvalue %Pos %boxed1, %Object %object, 1
877
+ ret %Pos %boxed2
878
+ }
879
+
880
+ define ccc %CObject @coercePosObj(%Pos %input) {
881
+ entry:
882
+ %object = extractvalue %Pos %input, 1
883
+ %isNull = icmp eq %Object %object, null
884
+ br i1 %isNull, label %done, label %next
885
+
886
+ next:
887
+ %environment = call %Environment @objectEnvironment(%Object %object)
888
+ br label %done
889
+
890
+ done:
891
+ %result = phi %CObject [ null, %entry ], [ %environment, %next ]
892
+ ret %CObject %result
893
+ }
894
+
826
895
 
827
896
  ; Scope domains
828
897
  !0 = !{!"types"}
@@ -1,10 +1,11 @@
1
1
  #ifndef EFFEKT_TYPES_C
2
2
  #define EFFEKT_TYPES_C
3
3
 
4
-
5
4
  typedef int64_t Int;
6
5
  typedef double Double;
7
6
  typedef uint8_t Byte;
7
+ typedef void* CObject;
8
+ typedef void (*Eraser)(void*);
8
9
 
9
10
  struct Header {
10
11
  uint64_t rc;
@@ -50,4 +51,8 @@ extern void shareNegative(struct Neg);
50
51
  extern void sharePositive(struct Pos);
51
52
  extern void shareStack(Stack);
52
53
 
54
+ extern CObject effekt_alloc(Eraser eraser, uint64_t size);
55
+ extern void effekt_share(CObject object);
56
+ extern void effekt_erase(CObject object);
57
+
53
58
  #endif
@@ -1,5 +1,5 @@
1
1
  <!doctype html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><title>Eclipse Public License 2.0 (EPL) | The Eclipse Foundation</title>
2
- <meta property="og:title" content="Eclipse Public License 2.0 (EPL) | The Eclipse Foundation"><meta name=twitter:title content="Eclipse Public License 2.0 (EPL) | The Eclipse Foundation"><meta name=description content="The Eclipse Foundation provides our global community of individuals and organisations with a mature, scalable, and business-friendly environment for open source …"><meta property="og:description" content="The Eclipse Foundation provides our global community of individuals and organisations with a mature, scalable, and business-friendly environment for open source …"><meta name=twitter:description content="The Eclipse Foundation provides our global community of individuals and organisations with a mature, scalable, and business-friendly environment for open source …"><meta name=author content="Wayne Beaton"><link href=/favicon.ico rel=icon type=image/x-icon><meta property="og:image" content="https://www.eclipse.org/images/og-image.jpg"><meta name=twitter:image content="https://www.eclipse.org/images/og-image.jpg"><meta name=twitter:card content="summary"><meta name=twitter:site content="@eclipsefdn"><meta name=twitter:creator content="@eclipsefdn"><meta property="og:url" content="https://www.eclipse.org/legal/epl-2.0/"><meta property="og:type" content="website"><meta property="og:site_name" content="Eclipse Foundation"><meta name=keywords content="epl,epl-2.0,legal,foundation,eclipse,eclipse public license,license,licenses"><meta name=generator content="Hugo 0.144.2"><link rel=canonical href=https://www.eclipse.org/legal/epl-2.0/><link rel=alternate href=https://www.eclipse.org//legal/epl-2.0/index.xml type=application/rss+xml title><script>(function(e,t,n,s,o){e[s]=e[s]||[],e[s].push({"gtm.start":(new Date).getTime(),event:"gtm.js"});var a=t.getElementsByTagName(n)[0],i=t.createElement(n),r=s!="dataLayer"?"&l="+s:"";i.async=!0,i.src="https://www.googletagmanager.com/gtm.js?id="+o+r,a.parentNode.insertBefore(i,a)})(window,document,"script","dataLayer","GTM-5WLCZXC")</script><script>var tableClasses="table"</script><link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel=stylesheet type=text/css> <script type="module" crossorigin src="/public/assets/legal/epl-2.0/index-B3AGZL5a.js"></script>
2
+ <meta property="og:title" content="Eclipse Public License 2.0 (EPL) | The Eclipse Foundation"><meta name=twitter:title content="Eclipse Public License 2.0 (EPL) | The Eclipse Foundation"><meta name=description content="The Eclipse Foundation provides our global community of individuals and organisations with a mature, scalable, and business-friendly environment for open source …"><meta property="og:description" content="The Eclipse Foundation provides our global community of individuals and organisations with a mature, scalable, and business-friendly environment for open source …"><meta name=twitter:description content="The Eclipse Foundation provides our global community of individuals and organisations with a mature, scalable, and business-friendly environment for open source …"><meta name=author content="Wayne Beaton"><link href=/favicon.ico rel=icon type=image/x-icon><meta property="og:image" content="https://www.eclipse.org/images/og-image.jpg"><meta name=twitter:image content="https://www.eclipse.org/images/og-image.jpg"><meta name=twitter:card content="summary"><meta name=twitter:site content="@eclipsefdn"><meta name=twitter:creator content="@eclipsefdn"><meta property="og:url" content="https://www.eclipse.org/legal/epl-2.0/"><meta property="og:type" content="website"><meta property="og:site_name" content="Eclipse Foundation"><meta name=keywords content="epl,epl-2.0,legal,foundation,eclipse,eclipse public license,license,licenses"><meta name=generator content="Hugo 0.144.2"><link rel=canonical href=https://www.eclipse.org/legal/epl-2.0/><link rel=alternate href=https://www.eclipse.org//legal/epl-2.0/index.xml type=application/rss+xml title><script>(function(e,t,n,s,o){e[s]=e[s]||[],e[s].push({"gtm.start":(new Date).getTime(),event:"gtm.js"});var a=t.getElementsByTagName(n)[0],i=t.createElement(n),r=s!="dataLayer"?"&l="+s:"";i.async=!0,i.src="https://www.googletagmanager.com/gtm.js?id="+o+r,a.parentNode.insertBefore(i,a)})(window,document,"script","dataLayer","GTM-5WLCZXC")</script><script>var tableClasses="table"</script><link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel=stylesheet type=text/css> <script type="module" crossorigin src="/public/assets/legal/epl-2.0/index-C_u-k0hP.js"></script>
3
3
  <link rel="modulepreload" crossorigin href="/public/assets/main-Bt8LvxVt.js">
4
4
  <link rel="modulepreload" crossorigin href="/public/assets/get-body-content-BSqVYN3a.js">
5
5
  <link rel="modulepreload" crossorigin href="/public/assets/generate-body-content-B3DBgq4n.js">