-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnotes.txt
1335 lines (821 loc) · 30.2 KB
/
notes.txt
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
pre_result = p_pre_affine
res0 = xf1_var0_eval(pre_result, internal_real_data, unit_rnd, gauss_rnd)
res1 = xf1_var1_eval(pre_result, internal_real_data, unit_rnd, gauss_rnd)
res2 = xf1_var2_eval(pre_result, internal_real_data, unit_rnd, gauss_rnd)
sum_result = res0 + res1 + res2
else if(this->static_target_function && this->static_target_function->sig.name == "dot" &&
this->static_target_function->sig.param_types.size() == 3 &&
static_target_function->built_in_func_impl.nonNull() &&
static_target_function->built_in_func_impl->builtInType() == BuiltInFunctionImpl::BuiltInType_DotProductBuiltInFunc)
{
assert(this->argument_expressions.size() == 3);
if(!this->argument_expressions[2]->isConstant())
throw BaseException("Third arg to dot(a, b, num_comp) must be constant");
int64 num_components;
try
{
VMState vmstate;
vmstate.func_args_start.push_back(0);
ValueRef res = this->argument_expressions[2]->exec(vmstate);
const IntValue* res_i = checkedCast<IntValue>(res.getPointer());
num_components = res_i->value;
}
catch(BaseException& e)
{
throw BaseException("Failed to eval third arg of dot(a, b, num_comp): " + e.what());
}
DotProductBuiltInFunc* dot_func = static_cast<DotProductBuiltInFunc*>(this->static_target_function->built_in_func_impl.getPointer());
// bounds check index.
assert(this->static_target_function->sig.param_types[0]->getType() == Type::VectorTypeType);
if(num_components <= 0 || num_components > (int64)dot_func->vector_type->num)
throw BaseException("Third argument to dot(a, b, num_comp) function is out of range." + errorContext(*this));
dot_func->setNumComponents((int)num_components);
}
if(
sig.param_types[0]->getType() == Type::VectorTypeType && // vector
sig.param_types[1]->getType() == Type::VectorTypeType) // and vector
{
if((static_cast<const VectorType*>(sig.param_types[0].getPointer())->elem_type->getType() == Type::FloatType || // vector of floats
static_cast<const VectorType*>(sig.param_types[0].getPointer())->elem_type->getType() == Type::DoubleType) && // or vector of doubles
(*sig.param_types[0] == *sig.param_types[1]) && // and argument types are the same
sig.param_types[2]->getType() == Type::IntType)
{
if(sig.name == "dot")
{
vector<FunctionDefinition::FunctionArg> args = makeFunctionArgPair("x", sig.param_types[0], "y", sig.param_types[1]);
args.push_back(FunctionDefinition::FunctionArg(sig.param_types[2], "num_components"));
FunctionDefinitionRef def = new FunctionDefinition(
SrcLocation::invalidLocation(),
-1, // order number
"dot", // name
args, // args
NULL, // body expr
static_cast<const VectorType*>(sig.param_types[0].getPointer())->elem_type, // return type
new DotProductBuiltInFunc(sig.param_types[0].downcast<VectorType>(),
/*has_third_num_comp_arg=*/true) // built in impl.
);
//this->sig_to_function_map.insert(std::make_pair(sig, def));
// NOTE: because dot with 3 args is unusual in that it has the mask 'baked into it', we need a unique DotProductBuiltInFunc impl each time.
// So don't add to function map, so that it isn't reused.
// However, we need to add it to unique_functions to prevent it from being deleted, as calling function expr doesn't hold a ref to it.
unique_functions.push_back(def);
return def;
}
}
}
//testMainFloatArg("def main(float x) float : dot([1.0, 2.0, 3.0, 4.0]v, [x, x, x, x]v, 1)", 2.0f, 2.0f);
//testMainFloatArg("def main(float x) float : dot([1.0, 2.0, 3.0, 4.0]v, [x, x, x, x]v, 2)", 2.0f, 6.0f);
// Build auto-generated functions (compare equal etc..) for types seen)
#if 0
vector<ASTNodeRef> auto_gen_func_defs;
for(auto it=parsed_types.begin(); it != parsed_types.end(); ++it)
{
const TypeVRef& type = *it;
conPrint(type->toString());
// Make compare equal function for type
if(type->requiresCompareEqualFunction())
{
if(type->getType() == Type::FunctionType)
continue; // TODO: implement function comparison
vector<FunctionDefinition::FunctionArg> compare_eq_args;
compare_eq_args.push_back(FunctionDefinition::FunctionArg(type, "a"));
compare_eq_args.push_back(FunctionDefinition::FunctionArg(type, "b"));
FunctionDefinitionRef compare_eq_func = new FunctionDefinition(
SrcLocation::invalidLocation(),
-1, // order number
"__compare_equal", // name
compare_eq_args, // arguments
ASTNodeRef(), // body expr
new Bool(), // declard return type
new CompareEqualBuiltInFunc(type, /*is_compare_not_equal=*/false) // built in func impl.
);
auto_gen_func_defs.push_back(compare_eq_func);
// Make compare not-equal func
FunctionDefinitionRef compare_neq_func = new FunctionDefinition(
SrcLocation::invalidLocation(),
-1, // order number
"__compare_not_equal", // name
compare_eq_args, // arguments
ASTNodeRef(), // body expr
new Bool(), // declard return type
new CompareEqualBuiltInFunc(type, /*is_compare_not_equal=*/true) // built in func impl.
);
auto_gen_func_defs.push_back(compare_neq_func);
}
}
linker.addTopLevelDefs(auto_gen_func_defs);
#endif
// conPrint("a_code: ");
// a_code->dump();
// conPrint("a_code->getType(): ");
// a_code->getType()->dump();
// conPrint("");
//
// conPrint("b_code: ");
// b_code->dump();
// conPrint("b_code->getType(): ");
// b_code->getType()->dump();
// conPrint("");
"N:\chaotica\trunk\user params\lyc_nicer_linears.flame" DE speed
non-winter
------------------
103.8
103.9
winter
---------------
93.6
93.4
non-winter
------------
min elapsed: 35.239476710557945 ns
min elapsed: 34.80492159724236 ns
min elapsed: 34.88389775156975 ns
pdj::aply: 22ns
winter
---------
min elapsed: 41.24441184103489 ns
min elapsed: 41.20492376387119 ns
min elapsed: 40.69134593009949 ns
1 trig call, med size values: std::cos(): 8.075055666267872 ns
4 trig calls, med size values, std::cos(): 23.731342516839504 ns
winter gnarl 1 thread
81
non-winter
88.4
88.4
Speed of running winter tests vs LLVM version
----------------------------------------------
6.0.0:
====================
4.8417684212327 s
4.894991885405034 s
4.8816621182486415 s
3.4
=======================
2.332595095038414 s
2.3739817291498184 s
2.3964389953762293 s
Winter:
testASMFuncDirect(): 7.194066420197487 ns
testASMFuncIndirect(): 7.277028635144234 ns
Dependent types
----------------
getElem(varray<int> a, int index {index >= 0 && index < length(a)} int : a[index]
appendChar(string s, char c) string { length(returned) = length(s) + 1 } : concat(s, toString(c))
addOne(int x) int { x + 1 } : x + 1
get_field(S, field_index) V # Where V is refcounted
increments return value (V) ref count.
decrements S ref count
f(V v_a) V
Decrements v_a ref count. (Consumes v_a)
a + b (Where a is of type V and b is of type V
returns result with ref count 1.
decrements a and b ref count.
//engine_builder.setRelocationModel(llvm::Reloc::Static);
//engine_builder.setCodeModel(llvm::CodeModel::Large);
Copyright 2009- Nicholas Chapman
Notes on adding built-in functions
==================================
Built-in functions are functions like constructors, field acess functions, compare_equal functions etc..
There are a couple of approachs to adding them to the set of functions in the program:
Eager Addition
--------------
As soon as we see e.g. a struct type, add constructors, field access functions etc.. for that structure.
Such functions may be unused, and so will have to wait until the dead function elim pass to be removed.
Problems with this approach include how to get the set of used types in a program.
Easy enough for structures since they must be explictly defined.
However consider the literal [1, 2]a, which has type array<int, 2>. The type of this won't be known during parsing.
Lazy addition
-------------
This approach is to add the function only when requested, e.g. add __compare_equal(array<float, 2>, array<float, 2>) when
trying to bind the function from the expression [1, 2]a == [3, 4]a.
This is possibly more efficient, since we don't have to add and then remove a bunch of functions.
However this requires a bunch of support code to make sure these functions are included in the reachable set etc..
Parsing precedence:
====================
links back to parseExpression are not shown.
General parsing principle is that back-links are not allowed unless at least one token has been comsumed. This avoids infinite parsing loops.
parseFunctionDefinition
|
parseFunctionDefinitionGivenName parseNamedConstant
| |
-------------------------------------------------
|
parseExpression
|
parseLetBLock
|
----------------------------------------
| |
| parseLet
parseTernaryConditionalExpression
parseBinaryLogicalExpression
parseBinaryBitwiseExpression
parseComparisonExpression
parseShiftExpression
parseAddSubExpression
parseMulDivExpression
parseUnaryExpression
parseHighPrecedenceExpression (function call, array subscript (or one element array literal??), field access)
parseBasicExpression
|
-------------------------------------------------------------------------------------------------------------------------------------
| | | | | |
parseLiteral parseIfExpression parseVariableExpression parseMapLiteralExpression parseArrayOrVectorOrTupleLiteral parseAnonFunction
OLD:
// TODO: parseExpression does nothing, also move this to top
parseLetBlock
|
---------------------------------------
| |
parseExpression parseLet
parseBinaryLogicalExpression |
parseComparisonExpression parseExpression
parseAddSubExpression
parseMulDivExpression
parseUnaryExpression
parseParenExpression
parseArraySubscriptExpression
parseBasicExpression
|
------------------------------------------------------------------------------------------------
| | | |
parseFieldExpression parseLiteral parseMapLiteralExpression parseArrayOrVectorLiteralOrArraySubscriptExpression
| |
-------------------------------------------------- parseExpression
| | |
parseIfExpression parseFunctionExpression parseVariableExpression
| |
parseLetBlock parseExpression
Detecting function arguments that aren't referenced
===================================================
Do a pass over function body.
At end of pass,
if all variables are bound:
any argument that is not referenced is not used.
Pattern Matching
================
let
x = elem(somearray, i)
in
match x
int: x + 2
error: 66
Alternatively:
==============
if_in_domain x = elem(somearray, i)
x + 2
else
66
OR
if inBounds(somearray, i)
elem(somearray, i) + 2
else
66
So, can define
def safeAccess(T container, int i) V :
if inBounds(container, i)
elem(container, i)
else
0
Proofs with integer value ranges
================================
i e [INT_MIN, INT_MAX]
&&
i >= 0
=>
i e [0, INT_MAX]
&& i < 10
=>
i e [0, 10)
def main(int i) int :
if
i >= 0 && i < 10
then
elem([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]v, i)
else
0
So
have variable i
Walk up stack
if find an if statement, where the current elem node is in the true branch, then we know the condition is true:
if condition is a binary and node, process each child node (each child node is true)
if node is a comparison expression:
If left child is variable i
if comparison == '>'
lower bound = max(lower bound, right child val + 1)
else if comparison == '>='
lower bound = max(lower bound, right child val)
FunctionDef: main(int) int (Declared ret type: int)
Let Block. lets:
Let, var_name = 's'
String literal, value='hello world'
in:
FunctionExpr; target: stringLength(string)
Variable, name=s, Let, bound_index=0
Reference counting
==================
suppose we have a string type that we want to pass by reference, and not allocate on the stack.
def f() string : "bleh"
Will return a new string value, which can be stored in mem as something like
struct stringRep
{
size_t refcount;
std::string string;
}
f implementation can be something like:
f():
stringRep* s = call allocateString(@global_bleh_string) # Will have initial ref count of 1
return s
lets say we have
def main() int :
countChars(f())
which is equivalent to:
fval = f() # fval has ref count 1 after this
countChars(fval)
which should be code-genned as
main():
stringRep* fval = call f()
res = call countChars(stringRep* fval)
decrementStringRefCount(fval) # f goes out of scope here
return res
where decrementStringRefCount is:
decrementStringRefCount(stringRep* s):
r = load s->refcount
if r == 1
call freeString(s)
else
r' = r - 1
store r' in s->refcount
We call decrementStringRefCount whenever a string goes 'out of scope'.
This can be at the end of the function that the string value was defined in.
For a tighter scope bound we could use the let block or whatever.
Reference counted values coming into scope
==========================================
As let statement literal: (named value)
def f() int :
let
str = "hello"
in
return 1
As return value from function as a let value: (named value)
def f() int :
let
str = getSomeString()
in
return 1
As string literal as a function argument
def f() int :
return stringLength("hello")
As return value from function as a function argument
def f() int :
return stringLength(getSomeString())
Rules for ref counting
======================
String literal
--------------
A string literal node will return a value with ref count 1, and is a 'cleaned-up' value. (As it introduces a string value into the current function)
Function Expression
-------------------
A function expression with type String is a 'cleaned-up' value. (As it introduces a string value into the current function.)
Structure constructor
---------------------
A constructor function will increase the ref count by 1 of a string argument to the constructor (as a reference is stored in the returned structure)
A structure field value is a 'cleaned-up' value.
Structure field accessor (GetField)
-----------------------------------
A getfield function will increase the ref count by 1 of a string value.
Cleaned-up values
======================
A 'cleaned-up' value will have its reference count decremented at the end of the function, and if the resulting count is zero, then it will be freed,
*unless* the AST node is the function body, e.g. if the value is being returned.
If the cleaned up value is a 'composite value' (array or structure of cleaned-up values)
then it will clean up any field value that needs to be cleaned up
Passing values by pointer
=========================
If an AST node's value type is pass-by-pointer:
emitLLVMCode() Should return a pointer to a mem location that will contain the value.
This location will either be from an alloca, or be return_val_ptr.
func def main
func call expr: elem()
array literal: [1, 2, 3, 4]
int literal: 1
Precedence
=============
Highest precedence at top.
() (Parentheses)
- (Unary minus)
* / (mult and div)
+ - (add and sub)
< <= > >= (comparison)
== != (eq / neq)
&& || (logical and / or)
Operator Overloading
=================================
Take the case:
def f(S s, T t) float : g(s + t)
We don't know the type of s + t until we replace s + t with op_add(s, t).
Since we need that to bind g, that means that the operator overloading replacement needs to be done
immediately after binding s and t, and before trying to bind g.
FunctionDef: makeLambda() function<float, float>
FunctionDef: anon_func_6(float) float
Mul Expression
Variable, name=x, Arg, bound_index=0
Variable, name=x, Arg, bound_index=0
FunctionDef: main() float (Declared ret type: float)
Let Block. lets:
Let, var_name = 'f'
FunctionExpr; target: makeLambda()
in:
FunctionExpr; runtime bound to let index 0
Float literal, value=2
Function expressions:
Bound to a global function definition:
-------------------------------------
e.g.
def f(int x) int : x+1 # Global function f
def main() int : f(1) # call to f
In this case we know that the global func def doesn't capture any variables.
So it doesn't need a closure. So we will just emit a call instruction to it directly.
Bound to an argument or let clause
----------------------------------
e.g.
def f(int x) int : x+1 # Global function f
def main() int :
let g = f # assign f to g
in
g(1) # Call g
In this case the target function may have captured some variables, so we will assume that the value
returned will be a closure.
Closures:
=============================================================
When returning functions from functions, we need to return the captured environment as well (closure)
The closure will look something like
struct SomeFuncCapturedVars
{
captured_var_1;
captured_var_2;
...
captured_var_N;
}
struct Closure
{
uint64 ref_count;
ReturnType (*theFunc) (arg0, arg1.. argn, BaseCapturedVars* captured_vars);
BaseCapturedVars // but actually.. SomeFuncCapturedVars
}
struct SomeFuncFullClosure
{
uint32 ref_count;
ReturnType (*theFunc) (arg0, arg1.. argn, BaseCapturedVars* captured_vars, );
SomeFuncCapturedVars
}
And theFunc is implemented as:
ReturnType theFunc (BaseCapturedVars* captured_vars, arg0, arg1.. argn)
{
// Downcast
SomeFuncCapturedVars* cap = (SomeFuncCapturedVars*)captured_vars;
// use cap and normal args.
}
Frame:
map<string, vector<FunctionDefinitionRef> > name_to_functions_map
Helpful things todo:
====================
Allow lets anywhere, particularly inside if statements.
Allow optional type declarations for let statements
Type Coercion
=============
Integer -> Float
----------------
This should be done iff the integer can be exactly represented by the float.
This should also only be done for constant expressions (not function calls etc..). Otherwise it will be impossible to check
that the result is exactly convertible as an integer.
Integer to float promotion in arithmetical expressions:
1 + 2.0 => 1.0 + 2.0
Promotion to match function return type:
def f() float : 1
Promotion to match required arguments for function expression:
def f(float a, float b)
f(1, 2) => f(1.0, 2.0)
iff there are no other functions such as f(float, int), or f(int, int) etc.., e.g. as long as the overloading
is not ambiguous.
Recursive type promotion:
1.0 + (2 + 3)
1.0 + 5 [replacement of constant subexpression with literal]
1.0 + 5.0 [type promotion]
1.0 + 2 + 3
1.0 + 2.0 + 3 [type promotion]
3.0 + 3 [replacement of constant subexpression with literal]
3.0 + 3.0 [type promotion]
6.0 [replacement of constant subexpression with literal]
1.0 / 2
Float -> Int
------------
Since floats can rarely be represented exactly as ints, and truncation may not be the desired behaviour for negative numbers,
type coercion of this kind should *not* be done.
Constant Folding
================
1 + 2
->
3
Passing structures by value
===========================
"It's a frontend task to lower the code to follow the vendor ABI."
...
"The calling convention can be complex
enough and operate with the language-dependent definitions (e.g. "C"
structs, etc.), thus frontend should lower such constructs as needed."
-Anton
From http://old.nabble.com/Passing-structures-by-value-on-Windows-td28766193.html
Return structures by value directly from functions.
===========================
LLVM can return structures by value directly from functions.
However if this is done on external functions, then it needs to match the platform ABI.
Expression type depends on:
Return type of function expressions:
e.g. f(1) depends on return type of f.
But that in turn depends on what f is bound to.
Binding of variables is by name only and so has no dependencies.
Binding of function expressions depends on type of argument subtrees, also on type of variable
expressions.
LLVMAnalysis.lib LLVMArchive.lib LLVMAsmParser.lib LLVMAsmPrinter.lib LLVMBitReader.lib LLVMBitWriter.lib LLVMCodeGen.lib LLVMCore.lib LLVMDebugger.lib LLVMExecutionEngine.lib LLVMHello.lib LLVMInstrumentation.lib LLVMInterpreter.lib LLVMipa.lib LLVMipo.lib LLVMJIT.lib LLVMLinker.lib LLVMScalarOpts.lib LLVMSelectionDAG.lib LLVMSupport.lib LLVMSystem.lib LLVMTarget.lib LLVMTransformUtils.lib LLVMX86AsmPrinter.lib LLVMX86CodeGen.lib
Runtime system
--------------
Build up LLVM code structure
compile whole thing using LLVM
Start worker threads
Make first work unit
Assign it to a worker thread work queue
wait until all worker threads are finished.
done.
Stages:
Lexing Stage
------------
Read text buffers, convert to token lists.
Parsing Stage
-------------
Convert token lists to abstract syntax trees
Type checking stage
-------------------
Object Layout stage
------------------------
Generate memory layouts for all structures
LLVM tree construction stage
-------------------
Generate LLVM tree structure corresponding to AST
LLVM codegen stage
------------------
Get LLVM to JIT compile all its stuff in tree structures
Create VM
------------
Get the VM ready to run, i.e. create worker threads
Get entry point function
------------------------
Get pointer to entry point function, e.g. main() or some other function
Make a call into that from client code
Control tranfers to VM.
VM creates work unit, puts on queue of worker thread
worker thread executes
worker thread sends done message back to VM
Vm returns control back to client code.
Type Memory Layout
------------------
Directly embedded types: must have fixed size known at compile time
byte, ubyte, int, uint, float, double,
tuple<T0, T1, .. TN> (as long as types Ti are all directly embedded types)
tuple<T, N> (as long as type T is directly embedded)
Otherwise, alloc in heap and store pointer to the object,
e.g. for tuple<string, string>:
{
String* a;
String* b;
}
class TypeLayout
{
}
class BasicTypeLayout
{
Type* value;
}
class FieldPosition
{
int offset; // in bytes
bool pointer;
Type* value;
}
class CompositeTypeLayout : TypeLayout
{
std::vector<FieldPosition> contents;
}
class Value
{
Primitive Types Description Literal Syntax example Memory size (B)
-------------------------------------------------------------------------------------------------------------------
byte 8 bit signed integer 8b 1
ubyte 8 bit unsigned integer 8ub 1
int 32 bit signed integer 8 4
uint 32 bit unsigned integer 8u 4
float 32 bit float 8.0f 4
double 64 bit float 8.0 8
string Unicode string "bleh" variable
tuple<T0, T1, ..., TN> Ordered tuple of types T0, T1, .. , TN (8, "hello") size of T0 + size of T1 + .. + sizeof of TN or variable if one of T0..TN are variable
map<T0, T1> Map from T0 to T1 {8 : "bleh", 10 : "hello"} variable
set<T> Set of elements of type T {1, 2, 3, 4} variable
array<T, n> Array of n T's [1, 2, 3, 4]a size of T * n or variable if T is variable
varray<T> Array of T's of some length (like std::vector) [1, 2, 3, 4]va variable
vector<T, n> Vector of N elements of float, bool or int type T. [1, 2, 3, 4]v size of T * n
function<T0, T1, ..., TN, R> Function from T0, T1, T2, .. , TN to R \(int a, int b)(a + 4*b) variable
list<T> Variable length list of 0 or more T's (std::vector) [1, 2, 3, 4]
flist<T, n> List of known length: n [1, 2, 3, 4]f