diff options
117 files changed, 4717 insertions, 6354 deletions
@@ -139,12 +139,6 @@ tests: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag @$(JVM) org.junit.runner.JUnitCore $(test_cp) @$(JVM) org.junit.runner.JUnitCore com.seaofnodes.simple.FuzzerWrap -spill-stats: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag - @[ -d build/objs ] || mkdir -p build/objs - @$(JVM) com.seaofnodes.simple.SpillStats - -.PHONY: spill-stats - fuzzer: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag @echo "fuzzing " $(test_cp) @$(JVM) org.junit.runner.JUnitCore com.seaofnodes.simple.FuzzerWrap @@ -182,5 +176,11 @@ tags: $(main_javas) $(test_javas) @rm -f TAGS @$(CTAGS) -e --recurse=yes --extra=+q --fields=+fksaiS $(SRC) $(TST) +spill-stats: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag + @[ -d build/objs ] || mkdir -p build/objs + @$(JVM) com.seaofnodes.simple.SpillStats + +.PHONY: spill-stats + .PHONY: build build: $(CLZDIR)/main/.mtag diff --git a/README.ja.md b/README.ja.md index df9119a1..d3503fc6 100644 --- a/README.ja.md +++ b/README.ja.md @@ -61,7 +61,7 @@ Simple 言語のスタイルは、C または Java のサブセットに倣っã� * [第21章](docs/chapter21/README.ja.md):命令エンコーディングと ELF。 * [第22章](docs/chapter22/README.ja.md):Simple の Hello, World! * [第23章](docs/chapter23/README.ja.md):メソッドと型の再検討。 -* 第24章:連鎖した条件分岐と SCCP。 +* [第24章](docs/chapter24/README.ja.md):連鎖した条件分岐と SCCP。 * 第25章:モジュール、分割コンパイル、不完全な型を使う SSA の構築。 ## 章をまたぐビルド @@ -70,7 +70,7 @@ The Simple language is styled after a subset of C or Java. * [Chapter 21](docs/chapter21/README.md): Instruction Encodings & ELF * [Chapter 22](docs/chapter22/README.md): A Simple Hello, World! * [Chapter 23](docs/chapter23/README.md): Methods and Types Revisited -* Chapter 24: Chained conditionals and SCCP +* [Chapter 24](docs/chapter24/README.md): Chained conditionals and SCCP * Chapter 25: Modules, Separate Compilation, and SSA Construction with Incomplete Types ## Building across chapters diff --git a/docs/chapter24/24-grammar.ja.md b/docs/chapter24/24-grammar.ja.md new file mode 100644 index 00000000..fd3fa232 --- /dev/null +++ b/docs/chapter24/24-grammar.ja.md @@ -0,0 +1,168 @@ +# 第24章の文法 + +[English](24-grammar.md) | 日本語 + +```antlrv4 +grammar SimpleLanguage; + +// Name lookup, assignable operands, type compatibility, and access permissions +// are checked by the compiler in addition to these syntax rules. +program : statement* EOF ; + +block : '{' statement* '}' ; + +statement + : block + | returnStatement + | ifStatement + | whileStatement + | forStatement + | breakStatement + | continueStatement + | structDeclaration + | declaration ';' + | assignment ';' + | ';' + ; + +returnStatement : 'return' assignment ';' ; +ifStatement : 'if' '(' assignment ')' statement ('else' statement)? ; +whileStatement : 'while' '(' assignment ')' statement ; +breakStatement : 'break' ';' ; +continueStatement : 'continue' ';' ; + +forStatement + : 'for' '(' (declaration | assignment)? ';' assignment? ';' assignment? ')' statement + ; + +structDeclaration : 'struct' IDENTIFIER '{' structMember* '}' ';' ; +structMember : methodDeclaration | statement ; + +// A method is an ordinary fixed function binding in a struct definition. +// The compiler supplies self; it is not written in parameterList. +// The general declaration rule also admits explicitly typed function fields. +methodDeclaration : 'val' bindingModifier? IDENTIFIER '=' functionExpression ';' ; + +declaration : declarationType binding (',' binding)* ; +declarationType : type | 'var' | 'val' ; +binding : bindingModifier? IDENTIFIER ('=' initializer)? ; +bindingModifier : '!' | '~' ; +// A declaration initializer consisting of the string "C" declares an extern +// symbol. Ordinary strings elsewhere are array-valued expressions. +initializer : assignment ; + +// The prefix qualifies the named struct reference, not an enclosing array. +// Each [] / [~] suffix qualifies its own array layer. ? requires a reference. +type + : functionType + | primitiveType typeSuffix* + | accessModifier? typeName typeSuffix* + ; +accessModifier : '!' | '~' ; +typeSuffix : '?' | '[]' | '[~]' ; +typeName : IDENTIFIER ('.' IDENTIFIER)* ; + +primitiveType + : 'int' | 'i8' | 'i16' | 'i32' | 'i64' + | 'u1' | 'u8' | 'u16' | 'u32' | 'byte' | 'bool' + | 'flt' | 'f32' | 'f64' + ; + +assignment : expression (assignmentOperator assignment)? ; +assignmentOperator + : '=' | '+=' | '-=' | '*=' | '/=' | '&=' | '|=' | '^=' + | '<<=' | '>>=' | '>>>=' + ; + +expression : logicalExpression ('?' assignment (':' assignment)?)? ; + +// Both logical operators short-circuit and associate to the right here. +logicalExpression : bitwiseExpression (('&&' | '||') logicalExpression)? ; + +bitwiseExpression + : equalityExpression (('&' | '|' | '^') equalityExpression)* + ; + +equalityExpression : comparisonExpression (('==' | '!=') comparisonExpression)* ; + +// Chained comparisons test adjacent operands and short-circuit. A chain must +// keep its direction; equality has lower precedence and does not join a chain. +comparisonExpression + : shiftExpression + ( (('<' | '<=') shiftExpression)+ | (('>' | '>=') shiftExpression)+ )? + ; + +shiftExpression + : additiveExpression (('<<' | '>>' | '>>>') additiveExpression)* + ; + +additiveExpression + : multiplicativeExpression (('+' | '-') multiplicativeExpression)* + ; + +multiplicativeExpression + : unaryExpression (('*' | '/') unaryExpression)* + ; + +unaryExpression + : ('-' | '!') unaryExpression + | updateOperator IDENTIFIER + | postfixExpression + ; + +// Prefix updates require a local name; postfix updates also allow fields +// and array elements. All updates require an assignable operand. +updateOperator : '++' | '--' ; +postfixExpression : primaryExpression postfixSuffix* updateOperator? ; +postfixSuffix : '.' IDENTIFIER | '[' assignment ']' | '#' | callSuffix | methodCallSuffix ; + +// For a fixed function-valued member, object.name(args) passes object as self. +// This overlaps ordinary field selection followed by a call syntactically; +// name/type resolution determines which call form applies. +methodCallSuffix : '.' IDENTIFIER callSuffix ; + +primaryExpression + : INTEGER_LITERAL + | FLOAT_LITERAL + | STRING_LITERAL + | CHARACTER_LITERAL + | 'true' + | 'false' + | 'null' + | IDENTIFIER + | '(' assignment ')' + | newExpression + | functionExpression + ; + +// A function is an expression bound with an ordinary declaration. +// Its last statement supplies the implicit result; return can exit earlier. +functionExpression : '{' parameterList? '->' statement* '}' ; +parameterList : (parameter ','?)+ ; +parameter : type bindingModifier? IDENTIFIER ; + +// Function types have unnamed, space-separated argument types. +// {int} is the zero-argument type; its function expression still uses ->. +functionType + : '{' type+ '->' type '}' '?'? + | '{' type '}' '?'? + ; + +callSuffix : '(' argumentList? ')' ; +argumentList : assignment (',' assignment)* ','? ; + +// Struct initialization uses a block; array allocation supplies a length. +newExpression : 'new' type ('[' assignment ']' | block)? ; + +INTEGER_LITERAL : '0' | [1-9] DIGIT* ; +FLOAT_LITERAL : DIGIT+ ('.' DIGIT* ('e' DIGIT+)? | 'e' '-'? DIGIT+) ; +STRING_LITERAL : '"' (ESCAPE | ~["\\])* '"' ; +CHARACTER_LITERAL : '\'' (ESCAPE | ~['\\]) '\'' ; +fragment ESCAPE : '\\' [0ntr\\'"] ; +IDENTIFIER : NON_DIGIT (NON_DIGIT | DIGIT)* ; +fragment NON_DIGIT : [a-zA-Z_] ; +fragment DIGIT : [0-9] ; +WHITESPACE : [ \t\r\n]+ -> skip ; +LINE_COMMENT : '//' ~[\r\n]* -> skip ; +BLOCK_COMMENT : '/*' .*? '*/' -> skip ; +``` diff --git a/docs/chapter24/24-grammar.md b/docs/chapter24/24-grammar.md new file mode 100644 index 00000000..22867355 --- /dev/null +++ b/docs/chapter24/24-grammar.md @@ -0,0 +1,168 @@ +# Grammar for Chapter 24 + +English | [日本語](24-grammar.ja.md) + +```antlrv4 +grammar SimpleLanguage; + +// Name lookup, assignable operands, type compatibility, and access permissions +// are checked by the compiler in addition to these syntax rules. +program : statement* EOF ; + +block : '{' statement* '}' ; + +statement + : block + | returnStatement + | ifStatement + | whileStatement + | forStatement + | breakStatement + | continueStatement + | structDeclaration + | declaration ';' + | assignment ';' + | ';' + ; + +returnStatement : 'return' assignment ';' ; +ifStatement : 'if' '(' assignment ')' statement ('else' statement)? ; +whileStatement : 'while' '(' assignment ')' statement ; +breakStatement : 'break' ';' ; +continueStatement : 'continue' ';' ; + +forStatement + : 'for' '(' (declaration | assignment)? ';' assignment? ';' assignment? ')' statement + ; + +structDeclaration : 'struct' IDENTIFIER '{' structMember* '}' ';' ; +structMember : methodDeclaration | statement ; + +// A method is an ordinary fixed function binding in a struct definition. +// The compiler supplies self; it is not written in parameterList. +// The general declaration rule also admits explicitly typed function fields. +methodDeclaration : 'val' bindingModifier? IDENTIFIER '=' functionExpression ';' ; + +declaration : declarationType binding (',' binding)* ; +declarationType : type | 'var' | 'val' ; +binding : bindingModifier? IDENTIFIER ('=' initializer)? ; +bindingModifier : '!' | '~' ; +// A declaration initializer consisting of the string "C" declares an extern +// symbol. Ordinary strings elsewhere are array-valued expressions. +initializer : assignment ; + +// The prefix qualifies the named struct reference, not an enclosing array. +// Each [] / [~] suffix qualifies its own array layer. ? requires a reference. +type + : functionType + | primitiveType typeSuffix* + | accessModifier? typeName typeSuffix* + ; +accessModifier : '!' | '~' ; +typeSuffix : '?' | '[]' | '[~]' ; +typeName : IDENTIFIER ('.' IDENTIFIER)* ; + +primitiveType + : 'int' | 'i8' | 'i16' | 'i32' | 'i64' + | 'u1' | 'u8' | 'u16' | 'u32' | 'byte' | 'bool' + | 'flt' | 'f32' | 'f64' + ; + +assignment : expression (assignmentOperator assignment)? ; +assignmentOperator + : '=' | '+=' | '-=' | '*=' | '/=' | '&=' | '|=' | '^=' + | '<<=' | '>>=' | '>>>=' + ; + +expression : logicalExpression ('?' assignment (':' assignment)?)? ; + +// Both logical operators short-circuit and associate to the right here. +logicalExpression : bitwiseExpression (('&&' | '||') logicalExpression)? ; + +bitwiseExpression + : equalityExpression (('&' | '|' | '^') equalityExpression)* + ; + +equalityExpression : comparisonExpression (('==' | '!=') comparisonExpression)* ; + +// Chained comparisons test adjacent operands and short-circuit. A chain must +// keep its direction; equality has lower precedence and does not join a chain. +comparisonExpression + : shiftExpression + ( (('<' | '<=') shiftExpression)+ | (('>' | '>=') shiftExpression)+ )? + ; + +shiftExpression + : additiveExpression (('<<' | '>>' | '>>>') additiveExpression)* + ; + +additiveExpression + : multiplicativeExpression (('+' | '-') multiplicativeExpression)* + ; + +multiplicativeExpression + : unaryExpression (('*' | '/') unaryExpression)* + ; + +unaryExpression + : ('-' | '!') unaryExpression + | updateOperator IDENTIFIER + | postfixExpression + ; + +// Prefix updates require a local name; postfix updates also allow fields +// and array elements. All updates require an assignable operand. +updateOperator : '++' | '--' ; +postfixExpression : primaryExpression postfixSuffix* updateOperator? ; +postfixSuffix : '.' IDENTIFIER | '[' assignment ']' | '#' | callSuffix | methodCallSuffix ; + +// For a fixed function-valued member, object.name(args) passes object as self. +// This overlaps ordinary field selection followed by a call syntactically; +// name/type resolution determines which call form applies. +methodCallSuffix : '.' IDENTIFIER callSuffix ; + +primaryExpression + : INTEGER_LITERAL + | FLOAT_LITERAL + | STRING_LITERAL + | CHARACTER_LITERAL + | 'true' + | 'false' + | 'null' + | IDENTIFIER + | '(' assignment ')' + | newExpression + | functionExpression + ; + +// A function is an expression bound with an ordinary declaration. +// Its last statement supplies the implicit result; return can exit earlier. +functionExpression : '{' parameterList? '->' statement* '}' ; +parameterList : (parameter ','?)+ ; +parameter : type bindingModifier? IDENTIFIER ; + +// Function types have unnamed, space-separated argument types. +// {int} is the zero-argument type; its function expression still uses ->. +functionType + : '{' type+ '->' type '}' '?'? + | '{' type '}' '?'? + ; + +callSuffix : '(' argumentList? ')' ; +argumentList : assignment (',' assignment)* ','? ; + +// Struct initialization uses a block; array allocation supplies a length. +newExpression : 'new' type ('[' assignment ']' | block)? ; + +INTEGER_LITERAL : '0' | [1-9] DIGIT* ; +FLOAT_LITERAL : DIGIT+ ('.' DIGIT* ('e' DIGIT+)? | 'e' '-'? DIGIT+) ; +STRING_LITERAL : '"' (ESCAPE | ~["\\])* '"' ; +CHARACTER_LITERAL : '\'' (ESCAPE | ~['\\]) '\'' ; +fragment ESCAPE : '\\' [0ntr\\'"] ; +IDENTIFIER : NON_DIGIT (NON_DIGIT | DIGIT)* ; +fragment NON_DIGIT : [a-zA-Z_] ; +fragment DIGIT : [0-9] ; +WHITESPACE : [ \t\r\n]+ -> skip ; +LINE_COMMENT : '//' ~[\r\n]* -> skip ; +BLOCK_COMMENT : '/*' .*? '*/' -> skip ; +``` diff --git a/docs/chapter24/Makefile b/docs/chapter24/Makefile new file mode 100644 index 00000000..12659b8f --- /dev/null +++ b/docs/chapter24/Makefile @@ -0,0 +1,12 @@ +GV := $(wildcard *.gv) +SVG := $(patsubst %.gv,%.svg,$(GV)) + +.PHONY: all +all: $(SVG) + +%.svg: %.gv + dot -Tsvg $< > $@ + +.PHONY: clean +clean: + @rm -f $(SVG) diff --git a/docs/chapter24/README.ja.md b/docs/chapter24/README.ja.md new file mode 100644 index 00000000..bf412061 --- /dev/null +++ b/docs/chapter24/README.ja.md @@ -0,0 +1,262 @@ +# 第24章: 関係演算の連鎖と疎な条件付き定数伝播 + +[English](README.md) | 日本語 + +この文書は [原文](README.md) の日本語訳です。 + +[前の章: 第23章](../chapter23/README.ja.md) | +[次の章: 第25章](../chapter25/README.ja.md) + +この章では、たとえば `(60 <= score < 90)` のような条件の *連鎖* を許し、中央の `score` を繰り返さずに済むようにします。 + +コンパイラの主な変更は、手続き間の疎な条件付き定数伝播(SCCP)です。呼び出しグラフの辺も発見する、楽観的な型の求解です。メモリは第11章の遅延分割に従います。BulkMemPhi はメモリ全体を表し、MemPhi は正確なエイリアスをマージし、割り当てはインスタンスフィールドの部分メモリを消費・生成します。SCCP 中、メモリ Phi は到達不能入力を無視し、割り当て結果は制御が到達するまで高いままです。第25章には、不完全な型のための大きな SSA 再設計、非公開のコンストラクタメモリ、分割コンパイルを残します。[バックポートのレビュー待ち一覧](../chapter-backports.md) を参照してください。 + +[linear](https://github.com/SeaOfNodes/Simple/tree/linear) ブランチ上の直線的な Git リビジョン履歴で [この章](https://github.com/SeaOfNodes/Simple/tree/linear-chapter24) を読み、前の章と [比較](https://github.com/SeaOfNodes/Simple/compare/linear-chapter23...linear-chapter24) することもできます。 + +この章の[完全な言語文法](24-grammar.ja.md)はこちらです。 + +## 関係比較の連鎖 + +関係比較の連鎖により、同じ変数を繰り返さず、連続する比較をすっきりと読みやすく書けます。 + +```java +if (min <= x && x < max) +``` + +は、次になります。 + +```java +if (min <= x < max) +``` + +この構文は場所を節約し、数学で範囲検査を書く方法に似た、直感的な条件にします。たとえば: + +```java +int score = 75; +if (60 <= score < 90) { + sys.io.p("Pass"); +} +``` + +これは `score` を繰り返さず、60以上90未満かを検査します。 + +`<=` と `>=` の両方を使うなど、逆向きの比較を混ぜる式は、Simple の方向規則では許されません。 + +```java +if (a <= b >= c) +``` + +### 演算子の方向規則 + +重ねた比較は、すべての比較演算子が同じ方向を「向く」場合 *だけ* 有効です。 + +- `<` と `<` +- `<` と `<=` +- `>` と `>` +- `>` と `>=` + +等値演算子(`==` と `!=`)は通常どおり、より低い優先順位を持ちます。関係演算の連鎖をつなぐ要素ではありません。 + +1つの連鎖で方向を混ぜることはできません。 + +```java +if (a <= b >= c) // Invalid +``` + +真偽値を使えば、比較を数値の文脈に強制できます。次は有効ですが、珍しい書き方です。 + +```java +return (0 < arg) > 1; +``` + +`(0 < arg)` の結果に応じて、次のいずれかになります。 + +```java +return 0 > 1; +``` + +または + +```java +return 1 > 1; +``` + +等値演算子もこの形式で有効ですが、比較より優先順位が低いため、 + +```java +a < b == c +``` + +は次のように解析されます。 + +```java +(a < b) == c +``` + +これは意図した連鎖比較とは違うかもしれません。より明示的な代替は次です。 + +```java +a < b && b == c +``` + +比較は任意の長さで連鎖でき、同じ方向を向く限り、異なる比較演算子を自由に混ぜられます。中間の各オペランドは1回だけ評価します。後のオペランドは、前の比較が成功した場合だけ評価するため、連鎖内の呼び出しや更新は短絡評価されます。 + +例: + +``` +return 0 < arg < arg+1 < 4; +``` + +### 注意が必要な境界例 + +```java +return 0 != arg != 1; +``` + +これは連鎖した不等比較ではなく、標準の優先順位規則により次のように解析します。 + +```java +return ((0 != arg) != 1); +``` + +```java +return a == b == c; +``` + +同様に、これは次のように解析します。 + +```java +return ((a == b) == c); +``` + +## 疎な条件付き定数伝播 + +[SCCP](https://en.wikipedia.org/wiki/Sparse_conditional_constant_propagation) は、これまで行ってきたピープホール最適化/定数畳み込みの、上から下へ進む版です。アルゴリズムの規則は文献でよく知られ、大学で一般に教えられています。[スライドの例](https://www.cse.psu.edu/~gxt29/teaching/cse522s23/slides/08monotoneFramework.pdf) があります。 + +- すでに束を持っています。 +- すでに SSA 形式を持っています。したがってアルゴリズムは *疎* です。 +- ノードから型への対応(`Node._type`)を持っています。 +- すでに伝達関数(`Node.compute`)を持っています。 + +すべての `_type` を、⊥ ではなく ⊤ に初期化し、すべてのノードをワークリストに置きます。そこからノードを取り、伝達関数 `node.compute()` を実行します。結果が `node._type` と変われば更新し、その出力側の隣接ノードをワークリストへ入れます。アサーションとデバッグ補助をすべて取り除いた簡略版は次のとおりです。 + +```java +while( (n = code._iter._work.pop()) != null ) { + Type nval = n.compute(); + if( n._type != nval ) { + assert n._type.isa(nval); // Types start high and always fall + n._type = nval; // Update type in Node + code._iter.addAll(n._outputs);// Neighbors might change, need to inspect + } +} +``` + +このアルゴリズムは必ず停止し、一般にはかなり速く、束と伝達関数の制限内での「最良の答え」である *不動点* に必ず到達します。得られる型はピープホール規則で見つけたものより単調に改善されます。その後、型が改善されたノードでピープホール規則を実行し、無関係なピープホール最適化が適用できるかを調べられます。たとえば新しく発見した定数が、計算を ConstantNode に置き換えます。 + +以下は SSA の擬似コードです。`phi` はマージを意味し、Simple の構文ではありません。 + +```text +int x0 = 1; // x0 = 1 +while( rand ) { + x1 = phi(x0,x2); // x1 = BOT = phi(1,BOT) + x2 = 2 - x1; // x2 = BOT = 2 - BOT +} +return x1 +``` + +SCCP がなければ、この小さなプログラムは `x` の計算を畳み込めません。見れば `x` は常に `1` とわかりますが、下から上へ進む悲観的手法は、x1 が BOT なので x2 が BOT、したがって x1 が BOT と判断します。行き詰まりを解くには楽観的手法が必要です。x1 が `1` と *仮定* すれば、x2 も `1` と発見できます。値の畳み込みは、ループ停止を証明したり、その条件と副作用を除去可能にしたりするものではありません。 + +アルゴリズムは左から右へ進み、変化がなくなったら停止します。 + +| 変数 | 初期 | x0=1 | x1=phi(1,T) | x2=2-x1 | x1=phi(1,1) | +|---|----|----|-----------|-------|-----------| +| x0 | T | 1 | 1 | 1 | 1 | +| x1 | T | T | 1 | 1 | 1 | +| x2 | T | T | T | 1 | 1 | + +### 条件付き + +制御フローがデータフローと同じグラフ内にあるため(これが Sea-of-Nodes の大きな要点です)、特別なことをする必要はなく、アルゴリズムはすでに *条件付き* です。ここでも例が役に立ちます。 + +再び SSA の擬似コードを使います。 + +```text +int x0 = 1; // x0 = 1 +while( rand ) { + x1 = phi(x0,x4); // x1 = BOT = phi(1,BOT) + if( x1 == 1 ) // Since x1 is BOT, both true and false arms are taken + x2 = 2 - x1; // x2 = BOT = 2 - BOT + else x3 = 99; // x3 = 99 + x4 = phi(x2,x3); // x4 = BOT = phi(BOT,99) +} +return x1 +``` + +再び左から右へ進みますが、今度はすべての経路が到達可能とは限りません。`if` の結果は Control 値の対で、経路が生きていれば `C`、そうでなければ `X` で示します。これは `x4 = phi(x2,x3)` の計算で使います。`PhiNode` は `if` の対応する制御入力 *も* 確認し、生きた経路だけをマージします。 + +| 変数 | 初期 | x0=1 | x1=phi(1,T) | 1 == 1? | x2=2-x1 | x3=99 | x4=phi(C/1,X/99) | x1=phi(1,1) | +|---|-----|----|-----------|---------|---------|---------|----------------|-----------| +| x0 | T | 1 | 1 | 1 | 1 | 1 | 1 | 1 | +| x1 | T | T | 1 | 1 | 1 | 1 | 1 | 1 | +| if | T | T | T | [C,X] | [C,X] | [C,X] | [C,X] | [C,X] | +| x2 | T | T | T | T | 1 | 1 | 1 | 1 | +| x3 | T | T | T | T | T | 99 | 99 | 99 | +| x4 | T | T | T | T | T | T | 1 | 1 | + +この種の条件付き定数伝播は、条件が真か偽と証明できると、最適化後のプログラムから検査と分岐を除去するので、非常に役立ちます。よくあるのが null 検査です。同じプログラムで、整数の代わりに null ポインタを使います。 + +```java +List head = notNullList(); +while( rand ) { + if( head ) head = new List(head,payload); + else { head = null; default_action(); } +} +``` + +`head` は非 null で始まるため、決して null にならず、`default_action` も起きません。ループは簡略化できます。 + +```java +List head = notNullList(); +while( rand ) { + head = new List(head,payload); +} +``` + +### 手続き間 + +**Simple** では、ここでもほぼ何もせず、SCCP を手続き間で実行します。`CallNode` は `FunNode` を呼び、`ReturnNode` は `CallEndNode` に戻り、まったく通常の方法で型情報を渡します。ただし問題が1つあります。`Call` と `Fun`、および `Return` と `CallEnd` の間に辺がありません。そのような辺が [呼び出しグラフ](https://en.wikipedia.org/wiki/Call_graph) を構成します。 + +通常の SCCP を拡張し、`Call` の関数ポインタ入力が変わり、新しい関数対象を得る時点を監視します。対象の数は有限なので、前の章で説明した *関数インデックス* で正確に表します。分割コンパイルでは、このコンパイル単位の外で呼ばれる無限の未知関数に対して、特別なインデックスを追加します。 + +`Call` で新しい *fidx* を見つけたら、`Call` と `Fun`、`Return` と `CallEnd` を *リンク* します。このリンクは、`Call` から `Fun`、そして `Call` の引数から `Fun` の `ParmNode` へ CFG 辺を追加したかのように動きます。`FunNode` は `RegionNode` を、`ParmNode` は `PhiNode` を拡張するため、同じ意味規則を使います。`Fun` は呼ばれると到達可能になり、`Parm` はすべての呼び出し引数をマージ(*meet*)します。同様に `CallEnd` は、すべての `Return` の *meet* を計算して、呼ばれたすべての関数の結果をマージします。 + +この *リンク* 段階はアルゴリズムの内部ループにいくつかの検査を加え、正確な呼び出しグラフも構築し、SCCP の手続き間実行を可能にします。進行中に新しい辺を少し発見する以外は、中核アルゴリズムは変わりません。不動点解で停止することが保証され、たとえば特定の呼び出しパラメータが、すべての呼び出し経路で定数、あるいは非 null と発見できることがあります。 + +## RegAlloc の改良: 低頻度側のループ分割を先に試す + +ループの Phi と後退辺は、ある命令で値が共存しなければならなくても、同じ生存区間に属する場合があります。この自己衝突は区間の分割を必要とします。第23章は Phi の定義と入力値をすぐに分割しました。この章では先に、高頻度の定義/後退辺をそのままにし、ループ外のコピーを試します。彩色が成功すれば各反復の移動を避けられます。2アドレス演算を含むほかの衝突は、既存の処理を保持します。 + +割り当て器は、どの Phi にこの機会を与えたかを記憶します。同じ Phi が再び自己衝突すると、次は通常の積極的な分割を使います。区間は各ラウンドで再構築するため、記録には Phi の同一性を使います。最初の試行でコピーを挿入しない、後退辺だけの衝突も対象です。その試行も、1回だけ許された遅延を消費しなければなりません。回帰テストは、安い最初の試行と、必須の代替処理の両方を確認します。 + +第21章の隣接コピー転送も引き継ぎます。彩色後、次の命令に唯一の使用がある場合、オペランドマスクが許し、2アドレスの結び付きを壊さなければコピー元レジスタを読めます。以下の表は、この整理と遅延メモリの前方移植を含みます。第22章の群には、以前の監査後に追加した移動0の C 戻り値 ABI 確認2件も含むようになりました(24ではなく26項目)。 + +`make spill-stats` を実行してください。全行は **第24章のコンパイラ**、最適化器のシード123、以前の群の表と同じソース/対象の組み合わせを使います。この Windows 結果は、x86 SystemV/Win64 と RISC-V/ARM SystemV を合わせ、遅延メモリの前方移植後に再測定したものです。 + +| プログラム群 | コンパイル数 | 残存する移動 | ループ重み付き移動 | +|---|---:|---:|---:| +| 第20章 | 39 | 320 | 439 | +| 第21章 | 52 | 420 | 952 | +| 第22章 | 26 | 67 | 67 | +| 第23章 | 30 | 78 | 225 | +| 第24章 | 67 | 422 | 1,325 | +| **合計** | **214** | **1,307** | **3,008** | + +`_spills` はレジスタ移動を含む残存 SplitNode を数えます。`_spillScaled` は `8^loopDepth` で重み付けするコスト推定で、測定されたメモリアクセスではありません。診断マシングラフはこの表の割り当てに寄与しません。報告器は、スピル期待値が異なっても、割り当ての合法性とネイティブ/エミュレーション結果を確認し、いずれの失敗でも失敗終了します。 + +後のコンパイラ修正より前の、元の2026-09-20割り当て器監査では、表の合計は1,332/2,956でした。低頻度側を先にする規則だけを無効にすると、同じコンパイラとプログラムは **1,338移動/2,962重み付き移動** でした。この規則は各6を減らします。RISC-V MergeSort の1ケースは1移動増えますが、ほかの MergeSort、Sieve、ARM ループの1ケースの改善が相殺します。集計測定はこの局所的な悪化を受け入れる根拠となります。ここでの改善は小さく、普遍的ではありません。 + +その監査で第20〜23章の群だけを見ると、第23章は933/1,745、第24章は900/1,614でした。それぞれの削減のうち、この割り当て器変更によるものは6だけです。残りは SCCP を含むほかのコンパイラ変更です。章だけの比較では、ヒューリスティックの効果を過大に見積もってしまいます。 + +以前の群は64ビット Person、ガード付き String、短いエミュレータ引数リストを保持します。改訂した Jig、BubbleSort、Newton、スタック引数入力は、既存のテストとともに第24章の群に属します。固定した String 処理対象は、インライン化の支配ノード走査で null 検査が欠けていたことも明らかにしました。その正しさの修正はヒューリスティック比較の両側に含めています。面積/コストのスピル順位付けは第25章に残します。 + +現在の関数ポインタ規則は、アドレスが直接呼び出し対象としてだけでなく、値として使われるたびに、未知の呼び出し側を保持します。これにより脱出解析なしで呼び出し可能な本体を保存しますが、Phi で選ばれた関数は一般的なパラメータ型を保持します。return のない String ケースは、今では未使用のハッシュ本体を除去し、分割を必要としません。ソース/対象の構成は変わりません。これらのグラフ変更は、上の低頻度側優先の割り当て器比較とは別です。 diff --git a/docs/chapter24/README.md b/docs/chapter24/README.md new file mode 100644 index 00000000..5a72ab42 --- /dev/null +++ b/docs/chapter24/README.md @@ -0,0 +1,325 @@ +# Chapter 24: Chaining Relationals and Sparse Conditional Constant Propagation + +English | [日本語](README.ja.md) + +[Previous: Chapter 23](../chapter23/README.md) | +[Next: Chapter 25](../chapter25/README.md) + +In this Chapter we allow *chaining* conditionals, e.g. `(60 <= score < 90)` +where `score` in the middle does not have to be repeated. + +The main compiler change is Interprocedural Sparse Conditional Constant +Propagation (SCCP): an optimistic type solve which also discovers call-graph +edges. Memory follows Chapter 11's lazy partitioning: BulkMemPhi represents +whole memory, MemPhi merges precise aliases, and allocations consume and produce +partial memory for their instance fields. During SCCP, memory Phis ignore +unreachable inputs and allocation results stay high until control reaches them. +Chapter 25 retains the larger incomplete-types SSA redesign, private constructor +memory, and separate compilation; see the [backport review queue](../chapter-backports.md). + + +You can also read [this chapter](https://github.com/SeaOfNodes/Simple/tree/linear-chapter24) in a linear Git revision history on the [linear](https://github.com/SeaOfNodes/Simple/tree/linear) branch and [compare](https://github.com/SeaOfNodes/Simple/compare/linear-chapter23...linear-chapter24) it to the previous chapter. + + +Here is the [complete language grammar](24-grammar.md) for this chapter. + +## Chaining Relational Tests + +Chaining relational tests offer a cleaner, more readable way to write chained +comparisons without repeating the same variable. + +```java +if (min <= x && x < max) +``` + +becomes + +```java +if (min <= x < max) +``` + +This syntax saves space and makes the condition more intuitive, similar to how +range checks are written in mathematics. E.g. + +```java +int score = 75; +if (60 <= score < 90) { + sys.io.p("Pass"); +} +``` +This checks if score is between 60 (inclusive) and 90 (exclusive), without repeating `score`. + +Expressions that mix opposite directions of comparison, like using both +`<=` and `>=`, are not allowed by Simple's direction rule. + +```java +if (a <= b >= c) +``` + + +### Operator direction rules +Stacked comparisons are *only* valid if all the comparison operators +"point" the same way: +- `<` with `<` +- `<` with `<=` +- `>` with `>` +- `>` with `>=` + +Equality operators (`==` and `!=`) have their normal, lower precedence; they +are not links in a relational chain. + +It is not allowed to mix directions in a single chain: +```java +if (a <= b >= c) // Invalid +``` + +Comparisons can be forced into numeric context using booleans. +This is valid but unusual: +```java +return (0 < arg) > 1; +``` +Depending on the result of (0 < arg) this will turn into either +```java +return 0 > 1; +``` +OR +```java +return 1 > 1; +``` +The equality operator is valid in this form, but since it has lower precedence than comparisons, +```java +a < b == c +``` +is parsed as: +```java +(a < b) == c +``` +This might not be the intended chained comparison. +A more explicit alternative is: +```java +a < b && b == c +``` +Comparisons can be chained together in any length, and different comparison operators may be +mixed freely as long as they point in the same direction. +Each intermediate operand is evaluated once. Later operands are evaluated only +if earlier comparisons succeed, so calls and updates in a chain short-circuit. + +E.g: +``` +return 0 < arg < arg+1 < 4; +``` + +### Tricky edge cases +```java +return 0 != arg != 1; +``` + +This is parsed by standard precedence rules as: +```java +return ((0 != arg) != 1); +``` +not as chained inequality. + +```java +return a == b == c; +``` +Similarly, this is parsed as: +```java +return ((a == b) == c); +``` + + + +## Sparse Conditional Constant Propagation + +[SCCP](https://en.wikipedia.org/wiki/Sparse_conditional_constant_propagation) +is the top-down version of the same peephole/constant-folding work we have +been doing all along. The rules for the algorithm are well known from the +literature and commonly taught at the college level; +[example slides](https://www.cse.psu.edu/~gxt29/teaching/cse522s23/slides/08monotoneFramework.pdf). + +- We have a lattice already +- We have SSA form already (hence the algorithm is *sparse*) +- We have a mapping from Nodes to Types (`Node._type`) +- We have transfer functions (`Node.compute`) already. + +We initialize all `_type` fields to ⊤ (as opposed to ⊥), and place all Nodes on +a worklist. We pull a Node from the worklist, run the transfer function +`node.compute()`, and if the result changes from `node._type` we update +`node._type` and put its output neighbors on the worklist. A simplified +version with all asserts and debug helpers removed: + +```java +while( (n = code._iter._work.pop()) != null ) { + Type nval = n.compute(); + if( n._type != nval ) { + assert n._type.isa(nval); // Types start high and always fall + n._type = nval; // Update type in Node + code._iter.addAll(n._outputs);// Neighbors might change, need to inspect + } +} +``` + +This algorithm always terminates (and generally fairly quickly) and always +reaches a *fixed point*, as "best answer" subject to the limits of our lattice +and transfer functions. The resulting types are monotonically better than +those found by the peephole rules; we can then run the peephole rules on nodes +with improved types, to see if unrelated peepholes can fire - such as newly +discovered constants replacing computations with ConstantNodes. + +The following is SSA pseudocode; `phi` denotes a merge, not Simple syntax. + +```text +int x0 = 1; // x0 = 1 +while( rand ) { + x1 = phi(x0,x2); // x1 = BOT = phi(1,BOT) + x2 = 2 - x1; // x2 = BOT = 2 - BOT +} +return x1 +``` + +Without SCCP, this small program cannot fold the computation of `x`. +A glance at the program tells us `x` must always be a `1` but +the bottom-up (pessimistic) approach decides that since x1 is BOT, x2 must be +BOT so x1 must be BOT. We need the optimistic approach to break the +stalemate, and just *assume* x1 is `1`, and then we can discover that x2 is +also a `1`. Folding the value does not prove the loop terminates or make +its condition and side effects removable. + + +The algorithm progresses from left to right and stops when no more changes +happen: + +|Var|init|x0=1|x1=phi(1,T)|x2=2-x1|x1=phi(1,1)| +|---|----|----|-----------|-------|-----------| +|x0 | T | 1 | 1 | 1 | 1 | +|x1 | T | T | 1 | 1 | 1 | +|x2 | T | T | T | 1 | 1 | + + + +### Conditional + +Since our control flow is in the same graph as our data flow (that's the major +point of Sea-of-Nodes!), we need not do anything special and our algorithm is +*conditional* already. Again an example is interesting: + +Again using SSA pseudocode: + +```text +int x0 = 1; // x0 = 1 +while( rand ) { + x1 = phi(x0,x4); // x1 = BOT = phi(1,BOT) + if( x1 == 1 ) // Since x1 is BOT, both true and false arms are taken + x2 = 2 - x1; // x2 = BOT = 2 - BOT + else x3 = 99; // x3 = 99 + x4 = phi(x2,x3); // x4 = BOT = phi(BOT,99) +} +return x1 +``` + +Again the algorithm progresses from left to right, although this time not all +paths are reachable. The `if` result is a pair of Control values, shown as +either `C` if the path is alive or `X` if not. This is used when we compute +`x4 = phi(x2,x3)`; the `PhiNode` ALSO checks the corresponding control input +from the `if` and only merges alive paths. + + +|Var|init |x0=1|x1=phi(1,T)| 1 == 1? | x2=2-x1 | x3=99 |x4=phi(C/1,X/99)|x1=phi(1,1)| +|---|-----|----|-----------|---------|---------|---------|----------------|-----------| +|x0 | T | 1 | 1 | 1 | 1 | 1 | 1 | 1 | +|x1 | T | T | 1 | 1 | 1 | 1 | 1 | 1 | +|if | T | T | T | [C,X] | [C,X] | [C,X] | [C,X] | [C,X] | +|x2 | T | T | T | T | 1 | 1 | 1 | 1 | +|x3 | T | T | T | T | T | 99 | 99 | 99 | +|x4 | T | T | T | T | T | T | 1 | 1 | + +This kind of conditional constant propagation really helps if a condition can +be proven true or false, as this removes a test and branch from the optimized +program. A common way this happens is with null tests; here is the same +program above, but using null pointers instead of integers: + +```java +List head = notNullList(); +while( rand ) { + if( head ) head = new List(head,payload); + else { head = null; default_action(); } +} +``` + +Here since `head` starts not-null, it can never be null and the +`default_action` can never happen, and the loop can +simplify: + +```java +List head = notNullList(); +while( rand ) { + head = new List(head,payload); +} +``` + +### Interprocedural + +In **Simple**, we let our SCCP run interprocedurally, again by (nearly) doing nothing: +`CallNodes` call `FunNodes`, `ReturnNodes` return to `CallEndNodes` and they +pass their type information along in exactly the normal way... except for one issue: +there are no edges between `Calls` and `Funs` (nor `Returns` and `CallEnds`). +Such edges make up a [Call Graph](https://en.wikipedia.org/wiki/Call_graph). + +We extend the normal SCCP algorithm to observe when a `Call`s function pointer +input changes - when it picks up new function targets. There are only a finite +number so we represent them exactly with *function indices* as described in an +earlier chapter. (Separate compilation adds a special index for the infinite +unknown functions that are called outside this compilation unit). + +Once we observe a new *fidx* at a `Call`, we *link* the `Call` with the `Fun`, +and the `Return` with the `CallEnd`. Such linkage acts exactly as-if we added +a CFG edge from the `Call` to the `Fun`, and the `Call`s arguments to the +`Fun`s `ParmNodes`. `FunNodes` extend `RegionNodes` (and `ParmNodes` extend +`PhiNodes`), so this linkage uses the same semantics. `Fun`s become reachable +when called; `Parm`s merge (*meet*) all calling arguments, and so on. +Similarly, `CallEnd`s merge results from all called functions, computing the +*meet* over all the `Return`s. + +This *link* step adds a few checks to our algorithm's inner loop, and also +builds a precise Call Graph which allows our SCCP to run interprocedurally. +Other than discovering a few new edges as the algorithm proceeds, the core +algorithm is unchanged. We are guaranteed to terminate with a fixed point +solution, and may discover e.g. certain call parameters are constants (or +e.g. not-null) on all calling paths. + + +## RegAlloc improvements: try cold loop splits first + +A loop Phi and its backedge can belong to one live range even though their +values must coexist at some instruction. This self-conflict requires splitting +the range. Chapter 23 split the Phi's definition and incoming values right away. +This chapter first leaves the hot definition/backedge alone and tries the +outside-loop copies. If coloring succeeds, it avoids moves on every iteration. +Other conflicts, including two-address operations, keep their existing handling. + +The allocator remembers which Phis have had this chance. If the same Phi +self-conflicts again, the next attempt uses the ordinary aggressive splitting. +The record uses Phi identity because live ranges are rebuilt each round. It +also covers a backedge-only conflict where the first attempt inserts no copy: +that attempt must still consume the one permitted delay. A regression checks +both the cheaper first attempt and the mandatory fallback. + +Rows are fixed test cohorts; columns are compiler chapters. Each cell gives +**Ops / RA / X**: executed ARM+RISC-V instructions, the subset emitted for +allocator copies/rematerializations, and x86's loop-weighted split-move estimate. +**Cases D / X** counts measured dynamic program/target cases and x86 compilations; +membership and inputs stay fixed across columns. Native-library work is excluded. +Chapter 20 has no encoder, hence no dynamic counts. Lower is better within each +metric; see the [measurement details](../regalloc-spills.md) for coverage. + +<!-- spill-matrix:start --> +| Test cohort | Cases D / X | Ch 20: Ops / RA / X | Ch 21: Ops / RA / X | Ch 22: Ops / RA / X | Ch 23: Ops / RA / X | Ch 24: Ops / RA / X | +|---|---:|---:|---:|---:|---:|---:| +| Ch 20 | 22 / 13 | — / — / 161 | 55,173 / 5,407 / 174 | 58,751 / 9,099 / 175 | 58,736 / 9,084 / 184 | 58,720 / 9,068 / 183 | +| Ch 21 | 20 / 18 | | 6,207 / 261 / 461 | 6,324 / 379 / 475 | 6,326 / 381 / 475 | 6,325 / 380 / 470 | +| Ch 22 | 14 / 8 | | | 198 / 60 / 7 | 194 / 56 / 7 | 194 / 56 / 7 | +| Ch 23 | 14 / 8 | | | | 630 / 160 / 36 | 630 / 160 / 36 | +| Ch 24 | 36 / 20 | | | | | 4,923 / 1,341 / 790 | +<!-- spill-matrix:end --> + diff --git a/src/test/java/com/seaofnodes/simple/progs/helloWorld.smp b/docs/chapter24/examples/A_helloWorld.smp index 07ff935f..07ff935f 100644 --- a/src/test/java/com/seaofnodes/simple/progs/helloWorld.smp +++ b/docs/chapter24/examples/A_helloWorld.smp diff --git a/docs/chapter24/examples/BubbleSort.smp b/docs/chapter24/examples/BubbleSort.smp new file mode 100644 index 00000000..938e3181 --- /dev/null +++ b/docs/chapter24/examples/BubbleSort.smp @@ -0,0 +1,37 @@ +// -*- mode: java; -*- + +// An implementation of +// https://sampleprograms.io/projects/bubble-sort/ +// +// Bubble sort, with reading (parsing) and writing (formatting) the data. + +val sort = { !sys.aryi64 nums -> + var done = false; + while( !done ) { + done = true; + for( var i = 0; i < nums.len-1; i++ ) + if( nums.buf[i] > nums.buf[i+1] ) { + int tmp = nums.buf[i]; + nums.buf[i] = nums.buf[i+1]; + nums.buf[i+1] = tmp; // Swap + done = false; + } + } +}; + +// Read from stdin a line of the form "[ 4, 3, 2, 1]" and print it sorted. +val main = { -> + // Parse array of numbers from stdin + var nums = sys.parseAryI64( sys.io.stdin() ); + if( !nums ) { + sys.io.p("stdin must look like [4, 3, 2, 1]"); + return 1; + } + + // Bubble sort array of integers + sort(nums); + + // Print a list of numbers to stdout + nums.str().write(1); + return 0; +}; diff --git a/docs/chapter24/font-awesome-4.7.0.zip b/docs/chapter24/font-awesome-4.7.0.zip Binary files differnew file mode 100644 index 00000000..b6bdb4bd --- /dev/null +++ b/docs/chapter24/font-awesome-4.7.0.zip diff --git a/docs/chapter24/ifg_trim.pdf b/docs/chapter24/ifg_trim.pdf Binary files differnew file mode 100644 index 00000000..d952fd4f --- /dev/null +++ b/docs/chapter24/ifg_trim.pdf diff --git a/docs/chapter24/lattice.gv b/docs/chapter24/lattice.gv new file mode 100644 index 00000000..8661082d --- /dev/null +++ b/docs/chapter24/lattice.gv @@ -0,0 +1,203 @@ +digraph Lattice { + compound = true; + // Define nodes + splines=false; + node [shape=circle, style=filled]; + nodesep=0.2; + ranksep=0.2; + + TOP [label=<<B>⊤</B >>, fillcolor=black, fontcolor=white]; + BOT [label=<<B>⊥</B>>, fillcolor=black, fontcolor=white]; + + // ---------------------- + // Control + XCTRL [label=<<B>⊤</B >:ctrl>, fillcolor=yellow, shape=oval]; + CTRL [label=<<B>⊥</B>:ctrl>, fillcolor=yellow, shape=oval]; + + TOP -> XCTRL; + XCTRL -> CTRL; + CTRL -> BOT; + + // ---------------------- + // Integers + INT_TOP [label=<<B>⊤</B >:int>, fillcolor=lightblue, shape=oval]; + INT_BOT [label=<<B>⊥</B>:int>, fillcolor=lightblue, shape=oval]; + + INT_HI [label="[min>max]" , fillcolor=lightblue, shape=oval]; + INT_XBOOL [label="[1...0]", fillcolor=lightblue, shape=oval]; + INT_CON [label="constants", fillcolor=lightblue, shape=oval]; + INT_CON0 [label="0", fillcolor=lightblue]; + INT_CON1 [label="1", fillcolor=lightblue]; + INT_BOOL [label="[0...1]", fillcolor=lightblue,shape=oval]; + INT_LO [label="[min<max]" , fillcolor=lightblue, shape=oval]; + + TOP -> INT_TOP; + INT_TOP -> INT_HI; + INT_HI -> INT_XBOOL; + INT_XBOOL -> INT_CON0; + INT_XBOOL -> INT_CON1; + INT_HI -> INT_CON; + INT_CON0 -> INT_BOOL; + INT_CON1 -> INT_BOOL; + INT_BOOL -> INT_LO; + INT_CON -> INT_LO; + INT_LO -> INT_BOT; + INT_BOT -> BOT; + + INT_CON0 -> INT_CON1 -> INT_CON [style=invis]; + + // ---------------------- + // Floats + FLT_TOP [label=<<B>⊤</B >:flt>, fillcolor=aqua, shape=oval]; + FLT_BOT [label=<<B>⊥</B>:flt>, fillcolor=aqua, shape=oval]; + + FLT_CON64 [label="64b consts\n[excludes\n32b consts]" , fillcolor=aqua, shape=oval]; + FLT_CON32 [label="32b consts", fillcolor=aqua, shape=oval]; + FLT_CONPI [label="3.14159...", fillcolor=aqua, shape=oval]; + FLT_X32 [label="~f32", fillcolor=aqua]; + FLT_CON0 [label="0." , fillcolor=aqua]; + FLT_32 [label="f32" , fillcolor=aqua]; + + TOP -> FLT_TOP; + FLT_TOP -> FLT_CON64 + FLT_TOP -> FLT_CONPI + FLT_CON64 -> FLT_BOT + FLT_CONPI -> FLT_BOT + + FLT_TOP -> FLT_X32; + FLT_X32 -> FLT_CON0; + FLT_X32 -> FLT_CON32; + FLT_CON0 -> FLT_32; + FLT_CON32 -> FLT_32; + FLT_32 -> FLT_BOT + + FLT_BOT -> BOT; + + FLT_CON0 -> FLT_CON32 -> FLT_CONPI -> FLT_CON64 [style=invis]; + + + // ---------------------- + // Pointers, just a boolean nil/not and a struct + PTR [shape=none, fillcolor=none, label=< + <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> + <TR><TD BGCOLOR="green"><FONT color="white">*ptr</FONT></TD></TR> + <TR><TD BGCOLOR="lightgreen">struct</TD></TR> + </TABLE> + >]; + PTR0 [shape=none, fillcolor=none, label=< + <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> + <TR><TD BGCOLOR="green"><FONT color="white">*ptr?</FONT></TD></TR> + <TR><TD BGCOLOR="lightgreen">struct</TD></TR> + </TABLE> + >]; + + TOP -> PTR; + PTR -> PTR0; + PTR0 -> BOT; + + // ---------------------- + // Structs + STRUCT_TOP [label=<<B>⊤</B >:struct>, fillcolor=lightgreen, shape=oval]; + STRUCT_BOT [label=<<B>⊥</B>:struct>, fillcolor=lightgreen, shape=oval]; + + STRUCT_S1 [shape=none, fillcolor=none, label=< + <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> + <TR><TD BGCOLOR="lightgreen">field</TD><TD BGCOLOR="lightblue:green" gradientangle="315">int/ptr</TD></TR> + </TABLE> + >]; + STRUCT_S2 [shape=none, fillcolor=none, label=< + <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> + <TR><TD BGCOLOR="lightgreen">field</TD><TD BGCOLOR="lightblue:green" gradientangle="315">int/ptr</TD></TR> + <TR><TD BGCOLOR="lightgreen">field</TD><TD BGCOLOR="lightblue:green" gradientangle="315">int/ptr</TD></TR> + </TABLE> + >]; + STRUCT_SN [shape=none, fillcolor=none, label=< + <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> + <TR><TD BGCOLOR="lightgreen">field</TD><TD BGCOLOR="lightblue:green" gradientangle="315">int/ptr</TD></TR> + <TR><TD BGCOLOR="lightgreen">... </TD><TD BGCOLOR="lightblue:green" gradientangle="315">int/ptr</TD></TR> + <TR><TD BGCOLOR="lightgreen">field</TD><TD BGCOLOR="lightblue:green" gradientangle="315">int/ptr</TD></TR> + </TABLE> + >]; + + + TOP -> STRUCT_TOP; + STRUCT_TOP -> STRUCT_S1; + STRUCT_TOP -> STRUCT_S2; + STRUCT_TOP -> STRUCT_SN; + STRUCT_S1 -> STRUCT_BOT; + STRUCT_S2 -> STRUCT_BOT; + STRUCT_SN -> STRUCT_BOT; + STRUCT_BOT -> BOT; + + STRUCT_S1 -> STRUCT_S2 -> STRUCT_SN [style=invis]; + + // ---------------------- + // Memory + MEM_TOP [label=<<B>⊤</B >:mem>, fillcolor=blue, fontcolor=white, shape=oval]; + MEM_BOT [label=<<B>⊥</B>:mem>, fillcolor=blue, fontcolor=white, shape=oval]; + MEM_ALIAS1 [label="#1" , fillcolor=blue, fontcolor=white]; + MEM_ALIASDOTS [label="..." , fillcolor=blue, fontcolor=white, shape=oval]; + MEM_ALIASN [label="#n" , fillcolor=blue, fontcolor=white]; + + TOP -> MEM_TOP; + MEM_TOP -> MEM_ALIAS1; + MEM_TOP -> MEM_ALIASDOTS; + MEM_TOP -> MEM_ALIASN; + MEM_ALIAS1 -> MEM_BOT; + MEM_ALIASDOTS -> MEM_BOT; + MEM_ALIASN -> MEM_BOT; + MEM_BOT -> BOT; + + MEM_ALIAS1 -> MEM_ALIASDOTS -> MEM_ALIASN [style=invis]; + + // ---------------------- + // Tuples + + TUPLE_TOP [label=<<B>⊤</B >:tuple>, fillcolor=pink, shape=oval]; + TUPLE_BOT [label=<<B>⊥</B>:tuple>, fillcolor=pink, shape=oval]; + + TUPLE1 [shape=none, fillcolor=none, label=< + <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> + <TH><TD BGCOLOR="pink">Tuple</TD></TH> + <TR><TD BGCOLOR="black" ><FONT color="white">type</FONT></TD></TR> + </TABLE> + >]; + TUPLE2 [shape=none, fillcolor=none, label=< + <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> + <TH><TD BGCOLOR="pink">Tuple</TD></TH> + <TR><TD BGCOLOR="black" ><FONT color="white">type</FONT></TD></TR> + <TR><TD BGCOLOR="black" ><FONT color="white">type</FONT></TD></TR> + </TABLE> + >]; + TUPLEN [shape=none, fillcolor=none, label=< + <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> + <TH><TD BGCOLOR="pink">Tuple</TD></TH> + <TR><TD BGCOLOR="black" ><FONT color="white">type</FONT></TD></TR> + <TR><TD BGCOLOR="black" ><FONT color="white">...</FONT></TD></TR> + <TR><TD BGCOLOR="black" ><FONT color="white">type</FONT></TD></TR> + </TABLE> + >]; + + + TOP -> TUPLE_TOP; + TUPLE_TOP -> TUPLE1; + TUPLE_TOP -> TUPLE2; + TUPLE_TOP -> TUPLEN; + TUPLE1 -> TUPLE_BOT; + TUPLE2 -> TUPLE_BOT; + TUPLEN -> TUPLE_BOT; + TUPLE_BOT -> BOT; + + // ---------------------- + // Additional customization + {rank=same; TOP;} + {rank=same; INT_TOP; FLT_TOP; XCTRL; PTR; STRUCT_TOP; MEM_TOP; TUPLE_TOP} + {rank=same; INT_CON; INT_CON0; INT_CON1; + FLT_CON32; FLT_CON64; FLT_CON0; FLT_CONPI; + STRUCT_S1; STRUCT_S2; STRUCT_SN; + MEM_ALIAS1; MEM_ALIASDOTS; MEM_ALIASN; + TUPLE1; TUPLE2; TUPLEN; + } + {rank=same; INT_BOT; FLT_BOT; CTRL; PTR0; STRUCT_BOT; MEM_BOT; TUPLE_BOT} + {rank=same; BOT;} +} diff --git a/docs/chapter24/lattice.svg b/docs/chapter24/lattice.svg new file mode 100644 index 00000000..e72b473b --- /dev/null +++ b/docs/chapter24/lattice.svg @@ -0,0 +1,691 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" + "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<!-- Generated by graphviz version 12.2.0 (20241103.1931) + --> +<!-- Title: Lattice Pages: 1 --> +<svg width="1330pt" height="584pt" + viewBox="0.00 0.00 1329.51 583.54" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> +<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 579.54)"> +<title>Lattice</title> +<polygon fill="white" stroke="none" points="-4,4 -4,-579.54 1325.51,-579.54 1325.51,4 -4,4"/> +<!-- TOP --> +<g id="node1" class="node"> +<title>TOP</title> +<ellipse fill="black" stroke="black" cx="641.51" cy="-554.42" rx="21.12" ry="21.12"/> +<text text-anchor="start" x="633.63" y="-549.99" font-family="Times New Roman,serif" font-weight="bold" font-size="14.00" fill="white">⊤</text> +</g> +<!-- XCTRL --> +<g id="node3" class="node"> +<title>XCTRL</title> +<ellipse fill="yellow" stroke="black" cx="36.51" cy="-492.79" rx="36.51" ry="18"/> +<text text-anchor="start" x="17.76" y="-488.74" font-family="Times New Roman,serif" font-weight="bold" font-size="14.00">⊤</text> +<text text-anchor="start" x="33.51" y="-488.74" font-family="Times New Roman,serif" font-size="14.00">:ctrl</text> +</g> +<!-- TOP->XCTRL --> +<g id="edge1" class="edge"> +<title>TOP->XCTRL</title> +<path fill="none" stroke="black" d="M620.33,-551.33C533.82,-542.8 206.01,-510.5 83.28,-498.4"/> +<polygon fill="black" stroke="black" points="83.86,-494.94 73.56,-497.44 83.17,-501.91 83.86,-494.94"/> +</g> +<!-- INT_TOP --> +<g id="node5" class="node"> +<title>INT_TOP</title> +<ellipse fill="lightblue" stroke="black" cx="316.51" cy="-492.79" rx="33.95" ry="18"/> +<text text-anchor="start" x="299.63" y="-488.74" font-family="Times New Roman,serif" font-weight="bold" font-size="14.00">⊤</text> +<text text-anchor="start" x="315.38" y="-488.74" font-family="Times New Roman,serif" font-size="14.00">:int</text> +</g> +<!-- TOP->INT_TOP --> +<g id="edge4" class="edge"> +<title>TOP->INT_TOP</title> +<path fill="none" stroke="black" d="M620.68,-549.6C568.33,-539.99 430.36,-514.68 359.64,-501.71"/> +<polygon fill="black" stroke="black" points="360.44,-498.29 349.97,-499.93 359.18,-505.18 360.44,-498.29"/> +</g> +<!-- FLT_TOP --> +<g id="node14" class="node"> +<title>FLT_TOP</title> +<ellipse fill="aqua" stroke="black" cx="494.51" cy="-492.79" rx="32.41" ry="18"/> +<text text-anchor="start" x="478.76" y="-488.74" font-family="Times New Roman,serif" font-weight="bold" font-size="14.00">⊤</text> +<text text-anchor="start" x="494.51" y="-488.74" font-family="Times New Roman,serif" font-size="14.00">:flt</text> +</g> +<!-- TOP->FLT_TOP --> +<g id="edge18" class="edge"> +<title>TOP->FLT_TOP</title> +<path fill="none" stroke="black" d="M621.99,-545.5C598.79,-536.09 559.6,-520.19 530.78,-508.5"/> +<polygon fill="black" stroke="black" points="532.29,-505.34 521.7,-504.82 529.65,-511.82 532.29,-505.34"/> +</g> +<!-- PTR --> +<g id="node22" class="node"> +<title>PTR</title> +<polygon fill="none" stroke="none" points="668.51,-519.29 614.51,-519.29 614.51,-466.29 668.51,-466.29 668.51,-519.29"/> +<polygon fill="green" stroke="none" points="623.51,-492.79 623.51,-515.29 659.51,-515.29 659.51,-492.79 623.51,-492.79"/> +<polygon fill="none" stroke="black" points="623.51,-492.79 623.51,-515.29 659.51,-515.29 659.51,-492.79 623.51,-492.79"/> +<text text-anchor="start" x="630.63" y="-498.99" font-family="Times New Roman,serif" font-size="14.00" fill="white">*ptr</text> +<polygon fill="lightgreen" stroke="none" points="623.51,-470.29 623.51,-492.79 659.51,-492.79 659.51,-470.29 623.51,-470.29"/> +<polygon fill="none" stroke="black" points="623.51,-470.29 623.51,-492.79 659.51,-492.79 659.51,-470.29 623.51,-470.29"/> +<text text-anchor="start" x="626.51" y="-476.49" font-family="Times New Roman,serif" font-size="14.00">struct</text> +</g> +<!-- TOP->PTR --> +<g id="edge33" class="edge"> +<title>TOP->PTR</title> +<path fill="none" stroke="black" d="M641.51,-532.9C641.51,-532.06 641.51,-531.22 641.51,-530.37"/> +<polygon fill="black" stroke="black" points="645.01,-530.61 641.51,-520.61 638.01,-530.61 645.01,-530.61"/> +</g> +<!-- STRUCT_TOP --> +<g id="node24" class="node"> +<title>STRUCT_TOP</title> +<ellipse fill="lightgreen" stroke="black" cx="746.51" cy="-492.79" rx="44.7" ry="18"/> +<text text-anchor="start" x="721.76" y="-488.74" font-family="Times New Roman,serif" font-weight="bold" font-size="14.00">⊤</text> +<text text-anchor="start" x="737.51" y="-488.74" font-family="Times New Roman,serif" font-size="14.00">:struct</text> +</g> +<!-- TOP->STRUCT_TOP --> +<g id="edge36" class="edge"> +<title>TOP->STRUCT_TOP</title> +<path fill="none" stroke="black" d="M659.8,-543.03C674.04,-534.94 694.24,-523.47 711.55,-513.64"/> +<polygon fill="black" stroke="black" points="713.07,-516.81 720.03,-508.83 709.61,-510.72 713.07,-516.81"/> +</g> +<!-- MEM_TOP --> +<g id="node29" class="node"> +<title>MEM_TOP</title> +<ellipse fill="blue" stroke="black" cx="998.51" cy="-492.79" rx="43.67" ry="18"/> +<text text-anchor="start" x="974.51" y="-488.74" font-family="Times New Roman,serif" font-weight="bold" font-size="14.00" fill="white">⊤</text> +<text text-anchor="start" x="990.26" y="-488.74" font-family="Times New Roman,serif" font-size="14.00" fill="white">:mem</text> +</g> +<!-- TOP->MEM_TOP --> +<g id="edge46" class="edge"> +<title>TOP->MEM_TOP</title> +<path fill="none" stroke="black" d="M662.51,-549.91C717.64,-540.7 867.72,-515.64 947.33,-502.34"/> +<polygon fill="black" stroke="black" points="947.77,-505.82 957.06,-500.72 946.62,-498.91 947.77,-505.82"/> +</g> +<!-- TUPLE_TOP --> +<g id="node34" class="node"> +<title>TUPLE_TOP</title> +<ellipse fill="pink" stroke="black" cx="1182.51" cy="-492.79" rx="42.65" ry="18"/> +<text text-anchor="start" x="1159.26" y="-488.74" font-family="Times New Roman,serif" font-weight="bold" font-size="14.00">⊤</text> +<text text-anchor="start" x="1175.01" y="-488.74" font-family="Times New Roman,serif" font-size="14.00">:tuple</text> +</g> +<!-- TOP->TUPLE_TOP --> +<g id="edge56" class="edge"> +<title>TOP->TUPLE_TOP</title> +<path fill="none" stroke="black" d="M662.72,-551.08C740.91,-542.46 1014.51,-512.31 1130.21,-499.56"/> +<polygon fill="black" stroke="black" points="1130.5,-503.05 1140.05,-498.47 1129.73,-496.09 1130.5,-503.05"/> +</g> +<!-- BOT --> +<g id="node2" class="node"> +<title>BOT</title> +<ellipse fill="black" stroke="black" cx="641.51" cy="-21.12" rx="21.12" ry="21.12"/> +<text text-anchor="start" x="633.63" y="-16.7" font-family="Times New Roman,serif" font-weight="bold" font-size="14.00" fill="white">⊥</text> +</g> +<!-- CTRL --> +<g id="node4" class="node"> +<title>CTRL</title> +<ellipse fill="yellow" stroke="black" cx="49.51" cy="-82.75" rx="36.51" ry="18"/> +<text text-anchor="start" x="30.76" y="-78.7" font-family="Times New Roman,serif" font-weight="bold" font-size="14.00">⊥</text> +<text text-anchor="start" x="46.51" y="-78.7" font-family="Times New Roman,serif" font-size="14.00">:ctrl</text> +</g> +<!-- XCTRL->CTRL --> +<g id="edge2" class="edge"> +<title>XCTRL->CTRL</title> +<path fill="none" stroke="black" d="M37.09,-474.38C39.15,-409.6 46.05,-191.88 48.57,-112.25"/> +<polygon fill="black" stroke="black" points="52.06,-112.73 48.88,-102.63 45.06,-112.51 52.06,-112.73"/> +</g> +<!-- CTRL->BOT --> +<g id="edge3" class="edge"> +<title>CTRL->BOT</title> +<path fill="none" stroke="black" d="M85.21,-78.15C191.74,-67.42 506.36,-35.74 608.84,-25.41"/> +<polygon fill="black" stroke="black" points="609.15,-28.9 618.75,-24.42 608.45,-21.94 609.15,-28.9"/> +</g> +<!-- INT_HI --> +<g id="node7" class="node"> +<title>INT_HI</title> +<ellipse fill="lightblue" stroke="black" cx="174.51" cy="-434.29" rx="53.91" ry="18"/> +<text text-anchor="middle" x="174.51" y="-429.24" font-family="Times New Roman,serif" font-size="14.00">[min>max]</text> +</g> +<!-- INT_TOP->INT_HI --> +<g id="edge5" class="edge"> +<title>INT_TOP->INT_HI</title> +<path fill="none" stroke="black" d="M289.8,-481.17C269.89,-473.25 242.26,-462.25 219.03,-453.01"/> +<polygon fill="black" stroke="black" points="220.37,-449.77 209.78,-449.33 217.78,-456.28 220.37,-449.77"/> +</g> +<!-- INT_BOT --> +<g id="node6" class="node"> +<title>INT_BOT</title> +<ellipse fill="lightblue" stroke="black" cx="329.51" cy="-82.75" rx="33.95" ry="18"/> +<text text-anchor="start" x="312.63" y="-78.7" font-family="Times New Roman,serif" font-weight="bold" font-size="14.00">⊥</text> +<text text-anchor="start" x="328.38" y="-78.7" font-family="Times New Roman,serif" font-size="14.00">:int</text> +</g> +<!-- INT_BOT->BOT --> +<g id="edge15" class="edge"> +<title>INT_BOT->BOT</title> +<path fill="none" stroke="black" d="M361.14,-75.7C420.84,-64.3 549.47,-39.71 609.47,-28.25"/> +<polygon fill="black" stroke="black" points="609.86,-31.73 619.03,-26.42 608.55,-24.86 609.86,-31.73"/> +</g> +<!-- INT_XBOOL --> +<g id="node8" class="node"> +<title>INT_XBOOL</title> +<ellipse fill="lightblue" stroke="black" cx="97.51" cy="-373.97" rx="33.95" ry="18"/> +<text text-anchor="middle" x="97.51" y="-368.92" font-family="Times New Roman,serif" font-size="14.00">[1...0]</text> +</g> +<!-- INT_HI->INT_XBOOL --> +<g id="edge6" class="edge"> +<title>INT_HI->INT_XBOOL</title> +<path fill="none" stroke="black" d="M153.47,-417.36C144.79,-410.78 134.6,-403.06 125.31,-396.03"/> +<polygon fill="black" stroke="black" points="127.71,-393.46 117.63,-390.21 123.48,-399.04 127.71,-393.46"/> +</g> +<!-- INT_CON --> +<g id="node9" class="node"> +<title>INT_CON</title> +<ellipse fill="lightblue" stroke="black" cx="174.51" cy="-282.65" rx="45.21" ry="18"/> +<text text-anchor="middle" x="174.51" y="-277.6" font-family="Times New Roman,serif" font-size="14.00">constants</text> +</g> +<!-- INT_HI->INT_CON --> +<g id="edge9" class="edge"> +<title>INT_HI->INT_CON</title> +<path fill="none" stroke="black" d="M174.51,-416C174.51,-390.27 174.51,-343.1 174.51,-312.31"/> +<polygon fill="black" stroke="black" points="178.01,-312.52 174.51,-302.52 171.01,-312.52 178.01,-312.52"/> +</g> +<!-- INT_CON0 --> +<g id="node10" class="node"> +<title>INT_CON0</title> +<ellipse fill="lightblue" stroke="black" cx="47.51" cy="-282.65" rx="18" ry="18"/> +<text text-anchor="middle" x="47.51" y="-277.6" font-family="Times New Roman,serif" font-size="14.00">0</text> +</g> +<!-- INT_XBOOL->INT_CON0 --> +<g id="edge7" class="edge"> +<title>INT_XBOOL->INT_CON0</title> +<path fill="none" stroke="black" d="M88.34,-356.59C80.82,-343.17 70.07,-323.96 61.49,-308.62"/> +<polygon fill="black" stroke="black" points="64.63,-307.08 56.69,-300.06 58.53,-310.5 64.63,-307.08"/> +</g> +<!-- INT_CON1 --> +<g id="node11" class="node"> +<title>INT_CON1</title> +<ellipse fill="lightblue" stroke="black" cx="97.51" cy="-282.65" rx="18" ry="18"/> +<text text-anchor="middle" x="97.51" y="-277.6" font-family="Times New Roman,serif" font-size="14.00">1</text> +</g> +<!-- INT_XBOOL->INT_CON1 --> +<g id="edge8" class="edge"> +<title>INT_XBOOL->INT_CON1</title> +<path fill="none" stroke="black" d="M97.51,-355.75C97.51,-343.47 97.51,-326.68 97.51,-312.39"/> +<polygon fill="black" stroke="black" points="101.01,-312.64 97.51,-302.64 94.01,-312.64 101.01,-312.64"/> +</g> +<!-- INT_LO --> +<g id="node13" class="node"> +<title>INT_LO</title> +<ellipse fill="lightblue" stroke="black" cx="174.51" cy="-141.25" rx="53.91" ry="18"/> +<text text-anchor="middle" x="174.51" y="-136.2" font-family="Times New Roman,serif" font-size="14.00">[min<max]</text> +</g> +<!-- INT_CON->INT_LO --> +<g id="edge13" class="edge"> +<title>INT_CON->INT_LO</title> +<path fill="none" stroke="black" d="M174.51,-264.17C174.51,-240.45 174.51,-199.04 174.51,-170.9"/> +<polygon fill="black" stroke="black" points="178.01,-171.25 174.51,-161.25 171.01,-171.25 178.01,-171.25"/> +</g> +<!-- INT_CON0->INT_CON1 --> +<!-- INT_BOOL --> +<g id="node12" class="node"> +<title>INT_BOOL</title> +<ellipse fill="lightblue" stroke="black" cx="97.51" cy="-196.45" rx="33.95" ry="18"/> +<text text-anchor="middle" x="97.51" y="-191.4" font-family="Times New Roman,serif" font-size="14.00">[0...1]</text> +</g> +<!-- INT_CON0->INT_BOOL --> +<g id="edge10" class="edge"> +<title>INT_CON0->INT_BOOL</title> +<path fill="none" stroke="black" d="M56.45,-266.6C63.5,-254.72 73.51,-237.87 81.88,-223.77"/> +<polygon fill="black" stroke="black" points="84.75,-225.79 86.85,-215.41 78.73,-222.22 84.75,-225.79"/> +</g> +<!-- INT_CON1->INT_CON --> +<!-- INT_CON1->INT_BOOL --> +<g id="edge11" class="edge"> +<title>INT_CON1->INT_BOOL</title> +<path fill="none" stroke="black" d="M97.51,-264.21C97.51,-253.25 97.51,-238.87 97.51,-226.25"/> +<polygon fill="black" stroke="black" points="101.01,-226.39 97.51,-216.39 94.01,-226.39 101.01,-226.39"/> +</g> +<!-- INT_BOOL->INT_LO --> +<g id="edge12" class="edge"> +<title>INT_BOOL->INT_LO</title> +<path fill="none" stroke="black" d="M117.34,-181.75C124.98,-176.47 133.91,-170.3 142.42,-164.42"/> +<polygon fill="black" stroke="black" points="144.27,-167.4 150.5,-158.83 140.29,-161.64 144.27,-167.4"/> +</g> +<!-- INT_LO->INT_BOT --> +<g id="edge14" class="edge"> +<title>INT_LO->INT_BOT</title> +<path fill="none" stroke="black" d="M210.07,-127.29C234.52,-118.37 266.93,-106.56 291.82,-97.49"/> +<polygon fill="black" stroke="black" points="292.71,-100.89 300.91,-94.17 290.31,-94.31 292.71,-100.89"/> +</g> +<!-- FLT_CON64 --> +<g id="node16" class="node"> +<title>FLT_CON64</title> +<ellipse fill="aqua" stroke="black" cx="564.51" cy="-282.65" rx="55.33" ry="40.66"/> +<text text-anchor="middle" x="564.51" y="-294.1" font-family="Times New Roman,serif" font-size="14.00">64b consts</text> +<text text-anchor="middle" x="564.51" y="-277.6" font-family="Times New Roman,serif" font-size="14.00">[excludes</text> +<text text-anchor="middle" x="564.51" y="-261.1" font-family="Times New Roman,serif" font-size="14.00">32b consts]</text> +</g> +<!-- FLT_TOP->FLT_CON64 --> +<g id="edge19" class="edge"> +<title>FLT_TOP->FLT_CON64</title> +<path fill="none" stroke="black" d="M500.48,-474.88C510.8,-443.88 532.35,-379.2 547.59,-333.44"/> +<polygon fill="black" stroke="black" points="550.9,-334.57 550.74,-323.98 544.26,-332.36 550.9,-334.57"/> +</g> +<!-- FLT_CONPI --> +<g id="node18" class="node"> +<title>FLT_CONPI</title> +<ellipse fill="aqua" stroke="black" cx="446.51" cy="-282.65" rx="48.79" ry="18"/> +<text text-anchor="middle" x="446.51" y="-277.6" font-family="Times New Roman,serif" font-size="14.00">3.14159...</text> +</g> +<!-- FLT_TOP->FLT_CONPI --> +<g id="edge20" class="edge"> +<title>FLT_TOP->FLT_CONPI</title> +<path fill="none" stroke="black" d="M490.33,-474.51C482.02,-438.11 463.32,-356.27 453.25,-312.16"/> +<polygon fill="black" stroke="black" points="456.69,-311.49 451.05,-302.52 449.86,-313.04 456.69,-311.49"/> +</g> +<!-- FLT_X32 --> +<g id="node19" class="node"> +<title>FLT_X32</title> +<ellipse fill="aqua" stroke="black" cx="333.51" cy="-373.97" rx="28.32" ry="28.32"/> +<text text-anchor="middle" x="333.51" y="-368.92" font-family="Times New Roman,serif" font-size="14.00">~f32</text> +</g> +<!-- FLT_TOP->FLT_X32 --> +<g id="edge23" class="edge"> +<title>FLT_TOP->FLT_X32</title> +<path fill="none" stroke="black" d="M474.77,-478.22C447.56,-458.14 398.22,-421.73 365.65,-397.69"/> +<polygon fill="black" stroke="black" points="367.88,-394.99 357.75,-391.86 363.72,-400.62 367.88,-394.99"/> +</g> +<!-- FLT_BOT --> +<g id="node15" class="node"> +<title>FLT_BOT</title> +<ellipse fill="aqua" stroke="black" cx="507.51" cy="-82.75" rx="32.41" ry="18"/> +<text text-anchor="start" x="491.76" y="-78.7" font-family="Times New Roman,serif" font-weight="bold" font-size="14.00">⊥</text> +<text text-anchor="start" x="507.51" y="-78.7" font-family="Times New Roman,serif" font-size="14.00">:flt</text> +</g> +<!-- FLT_BOT->BOT --> +<g id="edge29" class="edge"> +<title>FLT_BOT->BOT</title> +<path fill="none" stroke="black" d="M532.4,-70.67C554.98,-60.63 588.29,-45.81 612.16,-35.19"/> +<polygon fill="black" stroke="black" points="613.29,-38.51 621,-31.25 610.44,-32.12 613.29,-38.51"/> +</g> +<!-- FLT_CON64->FLT_BOT --> +<g id="edge21" class="edge"> +<title>FLT_CON64->FLT_BOT</title> +<path fill="none" stroke="black" d="M553.11,-242.68C542.05,-203.88 525.53,-145.95 515.71,-111.5"/> +<polygon fill="black" stroke="black" points="519.17,-110.89 513.06,-102.23 512.44,-112.81 519.17,-110.89"/> +</g> +<!-- FLT_CON32 --> +<g id="node17" class="node"> +<title>FLT_CON32</title> +<ellipse fill="aqua" stroke="black" cx="333.51" cy="-282.65" rx="50.33" ry="18"/> +<text text-anchor="middle" x="333.51" y="-277.6" font-family="Times New Roman,serif" font-size="14.00">32b consts</text> +</g> +<!-- FLT_CON32->FLT_CONPI --> +<!-- FLT_32 --> +<g id="node21" class="node"> +<title>FLT_32</title> +<ellipse fill="aqua" stroke="black" cx="333.51" cy="-196.45" rx="23.2" ry="23.2"/> +<text text-anchor="middle" x="333.51" y="-191.4" font-family="Times New Roman,serif" font-size="14.00">f32</text> +</g> +<!-- FLT_CON32->FLT_32 --> +<g id="edge27" class="edge"> +<title>FLT_CON32->FLT_32</title> +<path fill="none" stroke="black" d="M333.51,-264.21C333.51,-254.7 333.51,-242.59 333.51,-231.31"/> +<polygon fill="black" stroke="black" points="337.01,-231.51 333.51,-221.51 330.01,-231.51 337.01,-231.51"/> +</g> +<!-- FLT_CONPI->FLT_BOT --> +<g id="edge22" class="edge"> +<title>FLT_CONPI->FLT_BOT</title> +<path fill="none" stroke="black" d="M452.03,-264.56C462.62,-229.86 485.86,-153.69 498.65,-111.79"/> +<polygon fill="black" stroke="black" points="501.94,-112.98 501.51,-102.39 495.25,-110.93 501.94,-112.98"/> +</g> +<!-- FLT_CONPI->FLT_CON64 --> +<!-- FLT_X32->FLT_CON32 --> +<g id="edge25" class="edge"> +<title>FLT_X32->FLT_CON32</title> +<path fill="none" stroke="black" d="M333.51,-345.2C333.51,-334.71 333.51,-322.76 333.51,-312.19"/> +<polygon fill="black" stroke="black" points="337.01,-312.52 333.51,-302.52 330.01,-312.53 337.01,-312.52"/> +</g> +<!-- FLT_CON0 --> +<g id="node20" class="node"> +<title>FLT_CON0</title> +<ellipse fill="aqua" stroke="black" cx="251.51" cy="-282.65" rx="18.08" ry="18.08"/> +<text text-anchor="middle" x="251.51" y="-277.6" font-family="Times New Roman,serif" font-size="14.00">0.</text> +</g> +<!-- FLT_X32->FLT_CON0 --> +<g id="edge24" class="edge"> +<title>FLT_X32->FLT_CON0</title> +<path fill="none" stroke="black" d="M314.9,-352.7C301.83,-338.47 284.38,-319.46 271.1,-304.99"/> +<polygon fill="black" stroke="black" points="273.81,-302.77 264.47,-297.77 268.65,-307.5 273.81,-302.77"/> +</g> +<!-- FLT_CON0->FLT_CON32 --> +<!-- FLT_CON0->FLT_32 --> +<g id="edge26" class="edge"> +<title>FLT_CON0->FLT_32</title> +<path fill="none" stroke="black" d="M263.96,-268.86C276.06,-256.44 294.74,-237.26 309.69,-221.91"/> +<polygon fill="black" stroke="black" points="312.03,-224.53 316.5,-214.92 307.01,-219.64 312.03,-224.53"/> +</g> +<!-- FLT_32->FLT_BOT --> +<g id="edge28" class="edge"> +<title>FLT_32->FLT_BOT</title> +<path fill="none" stroke="black" d="M353.13,-183.63C383.19,-163.99 440.9,-126.28 476.61,-102.94"/> +<polygon fill="black" stroke="black" points="478.34,-105.99 484.79,-97.59 474.51,-100.13 478.34,-105.99"/> +</g> +<!-- PTR0 --> +<g id="node23" class="node"> +<title>PTR0</title> +<polygon fill="none" stroke="none" points="668.51,-109.25 614.51,-109.25 614.51,-56.25 668.51,-56.25 668.51,-109.25"/> +<polygon fill="green" stroke="none" points="623.51,-82.75 623.51,-105.25 659.51,-105.25 659.51,-82.75 623.51,-82.75"/> +<polygon fill="none" stroke="black" points="623.51,-82.75 623.51,-105.25 659.51,-105.25 659.51,-82.75 623.51,-82.75"/> +<text text-anchor="start" x="627.63" y="-88.95" font-family="Times New Roman,serif" font-size="14.00" fill="white">*ptr?</text> +<polygon fill="lightgreen" stroke="none" points="623.51,-60.25 623.51,-82.75 659.51,-82.75 659.51,-60.25 623.51,-60.25"/> +<polygon fill="none" stroke="black" points="623.51,-60.25 623.51,-82.75 659.51,-82.75 659.51,-60.25 623.51,-60.25"/> +<text text-anchor="start" x="626.51" y="-66.45" font-family="Times New Roman,serif" font-size="14.00">struct</text> +</g> +<!-- PTR->PTR0 --> +<g id="edge34" class="edge"> +<title>PTR->PTR0</title> +<path fill="none" stroke="black" d="M641.51,-466.52C641.51,-396.01 641.51,-202.44 641.51,-120.34"/> +<polygon fill="black" stroke="black" points="645.01,-120.58 641.51,-110.58 638.01,-120.58 645.01,-120.58"/> +</g> +<!-- PTR0->BOT --> +<g id="edge35" class="edge"> +<title>PTR0->BOT</title> +<path fill="none" stroke="black" d="M641.51,-56.46C641.51,-55.58 641.51,-54.7 641.51,-53.81"/> +<polygon fill="black" stroke="black" points="645.01,-53.9 641.51,-43.9 638.01,-53.9 645.01,-53.9"/> +</g> +<!-- STRUCT_S1 --> +<g id="node26" class="node"> +<title>STRUCT_S1</title> +<polygon fill="none" stroke="none" points="741.38,-300.65 663.63,-300.65 663.63,-264.65 741.38,-264.65 741.38,-300.65"/> +<polygon fill="lightgreen" stroke="none" points="671.63,-273.4 671.63,-291.9 698.38,-291.9 698.38,-273.4 671.63,-273.4"/> +<polygon fill="none" stroke="black" points="671.63,-273.4 671.63,-291.9 698.38,-291.9 698.38,-273.4 671.63,-273.4"/> +<text text-anchor="start" x="672.63" y="-277.6" font-family="Times New Roman,serif" font-size="14.00">field</text> +<defs> +<linearGradient id="l_0" gradientUnits="userSpaceOnUse" x1="703.51" y1="-289.19" x2="728.26" y2="-276.11" > +<stop offset="0" style="stop-color:lightblue;stop-opacity:1.;"/> +<stop offset="1" style="stop-color:green;stop-opacity:1.;"/> +</linearGradient> +</defs> +<polygon fill="url(#l_0)" stroke="none" points="698.38,-273.4 698.38,-291.9 733.38,-291.9 733.38,-273.4 698.38,-273.4"/> +<polygon fill="none" stroke="black" points="698.38,-273.4 698.38,-291.9 733.38,-291.9 733.38,-273.4 698.38,-273.4"/> +<text text-anchor="start" x="699.38" y="-277.6" font-family="Times New Roman,serif" font-size="14.00">int/ptr</text> +</g> +<!-- STRUCT_TOP->STRUCT_S1 --> +<g id="edge37" class="edge"> +<title>STRUCT_TOP->STRUCT_S1</title> +<path fill="none" stroke="black" d="M742.68,-474.51C735.02,-437.92 717.75,-355.45 708.55,-311.5"/> +<polygon fill="black" stroke="black" points="712.02,-311 706.54,-301.93 705.17,-312.43 712.02,-311"/> +</g> +<!-- STRUCT_S2 --> +<g id="node27" class="node"> +<title>STRUCT_S2</title> +<polygon fill="none" stroke="none" points="841.38,-309.15 755.63,-309.15 755.63,-256.15 841.38,-256.15 841.38,-309.15"/> +<polygon fill="lightgreen" stroke="none" points="763.63,-282.65 763.63,-305.15 794.38,-305.15 794.38,-282.65 763.63,-282.65"/> +<polygon fill="none" stroke="black" points="763.63,-282.65 763.63,-305.15 794.38,-305.15 794.38,-282.65 763.63,-282.65"/> +<text text-anchor="start" x="766.63" y="-288.85" font-family="Times New Roman,serif" font-size="14.00">field</text> +<defs> +<linearGradient id="l_1" gradientUnits="userSpaceOnUse" x1="800.1" y1="-301.86" x2="827.67" y2="-285.95" > +<stop offset="0" style="stop-color:lightblue;stop-opacity:1.;"/> +<stop offset="1" style="stop-color:green;stop-opacity:1.;"/> +</linearGradient> +</defs> +<polygon fill="url(#l_1)" stroke="none" points="794.38,-282.65 794.38,-305.15 833.38,-305.15 833.38,-282.65 794.38,-282.65"/> +<polygon fill="none" stroke="black" points="794.38,-282.65 794.38,-305.15 833.38,-305.15 833.38,-282.65 794.38,-282.65"/> +<text text-anchor="start" x="797.38" y="-288.85" font-family="Times New Roman,serif" font-size="14.00">int/ptr</text> +<polygon fill="lightgreen" stroke="none" points="763.63,-260.15 763.63,-282.65 794.38,-282.65 794.38,-260.15 763.63,-260.15"/> +<polygon fill="none" stroke="black" points="763.63,-260.15 763.63,-282.65 794.38,-282.65 794.38,-260.15 763.63,-260.15"/> +<text text-anchor="start" x="766.63" y="-266.35" font-family="Times New Roman,serif" font-size="14.00">field</text> +<defs> +<linearGradient id="l_2" gradientUnits="userSpaceOnUse" x1="800.1" y1="-279.36" x2="827.67" y2="-263.45" > +<stop offset="0" style="stop-color:lightblue;stop-opacity:1.;"/> +<stop offset="1" style="stop-color:green;stop-opacity:1.;"/> +</linearGradient> +</defs> +<polygon fill="url(#l_2)" stroke="none" points="794.38,-260.15 794.38,-282.65 833.38,-282.65 833.38,-260.15 794.38,-260.15"/> +<polygon fill="none" stroke="black" points="794.38,-260.15 794.38,-282.65 833.38,-282.65 833.38,-260.15 794.38,-260.15"/> +<text text-anchor="start" x="797.38" y="-266.35" font-family="Times New Roman,serif" font-size="14.00">int/ptr</text> +</g> +<!-- STRUCT_TOP->STRUCT_S2 --> +<g id="edge38" class="edge"> +<title>STRUCT_TOP->STRUCT_S2</title> +<path fill="none" stroke="black" d="M751.03,-474.51C759.53,-440.16 778.05,-365.34 789.28,-319.95"/> +<polygon fill="black" stroke="black" points="792.67,-320.83 791.67,-310.28 785.87,-319.15 792.67,-320.83"/> +</g> +<!-- STRUCT_SN --> +<g id="node28" class="node"> +<title>STRUCT_SN</title> +<polygon fill="none" stroke="none" points="941.38,-320.4 855.63,-320.4 855.63,-244.9 941.38,-244.9 941.38,-320.4"/> +<polygon fill="lightgreen" stroke="none" points="863.63,-293.9 863.63,-316.4 894.38,-316.4 894.38,-293.9 863.63,-293.9"/> +<polygon fill="none" stroke="black" points="863.63,-293.9 863.63,-316.4 894.38,-316.4 894.38,-293.9 863.63,-293.9"/> +<text text-anchor="start" x="866.63" y="-300.1" font-family="Times New Roman,serif" font-size="14.00">field</text> +<defs> +<linearGradient id="l_3" gradientUnits="userSpaceOnUse" x1="900.1" y1="-313.11" x2="927.67" y2="-297.2" > +<stop offset="0" style="stop-color:lightblue;stop-opacity:1.;"/> +<stop offset="1" style="stop-color:green;stop-opacity:1.;"/> +</linearGradient> +</defs> +<polygon fill="url(#l_3)" stroke="none" points="894.38,-293.9 894.38,-316.4 933.38,-316.4 933.38,-293.9 894.38,-293.9"/> +<polygon fill="none" stroke="black" points="894.38,-293.9 894.38,-316.4 933.38,-316.4 933.38,-293.9 894.38,-293.9"/> +<text text-anchor="start" x="897.38" y="-300.1" font-family="Times New Roman,serif" font-size="14.00">int/ptr</text> +<polygon fill="lightgreen" stroke="none" points="863.63,-271.4 863.63,-293.9 894.38,-293.9 894.38,-271.4 863.63,-271.4"/> +<polygon fill="none" stroke="black" points="863.63,-271.4 863.63,-293.9 894.38,-293.9 894.38,-271.4 863.63,-271.4"/> +<text text-anchor="start" x="869.63" y="-277.6" font-family="Times New Roman,serif" font-size="14.00">...  </text> +<defs> +<linearGradient id="l_4" gradientUnits="userSpaceOnUse" x1="900.1" y1="-290.61" x2="927.67" y2="-274.7" > +<stop offset="0" style="stop-color:lightblue;stop-opacity:1.;"/> +<stop offset="1" style="stop-color:green;stop-opacity:1.;"/> +</linearGradient> +</defs> +<polygon fill="url(#l_4)" stroke="none" points="894.38,-271.4 894.38,-293.9 933.38,-293.9 933.38,-271.4 894.38,-271.4"/> +<polygon fill="none" stroke="black" points="894.38,-271.4 894.38,-293.9 933.38,-293.9 933.38,-271.4 894.38,-271.4"/> +<text text-anchor="start" x="897.38" y="-277.6" font-family="Times New Roman,serif" font-size="14.00">int/ptr</text> +<polygon fill="lightgreen" stroke="none" points="863.63,-248.9 863.63,-271.4 894.38,-271.4 894.38,-248.9 863.63,-248.9"/> +<polygon fill="none" stroke="black" points="863.63,-248.9 863.63,-271.4 894.38,-271.4 894.38,-248.9 863.63,-248.9"/> +<text text-anchor="start" x="866.63" y="-255.1" font-family="Times New Roman,serif" font-size="14.00">field</text> +<defs> +<linearGradient id="l_5" gradientUnits="userSpaceOnUse" x1="900.1" y1="-268.11" x2="927.67" y2="-252.2" > +<stop offset="0" style="stop-color:lightblue;stop-opacity:1.;"/> +<stop offset="1" style="stop-color:green;stop-opacity:1.;"/> +</linearGradient> +</defs> +<polygon fill="url(#l_5)" stroke="none" points="894.38,-248.9 894.38,-271.4 933.38,-271.4 933.38,-248.9 894.38,-248.9"/> +<polygon fill="none" stroke="black" points="894.38,-248.9 894.38,-271.4 933.38,-271.4 933.38,-248.9 894.38,-248.9"/> +<text text-anchor="start" x="897.38" y="-255.1" font-family="Times New Roman,serif" font-size="14.00">int/ptr</text> +</g> +<!-- STRUCT_TOP->STRUCT_SN --> +<g id="edge39" class="edge"> +<title>STRUCT_TOP->STRUCT_SN</title> +<path fill="none" stroke="black" d="M759.21,-475.24C782.17,-443.49 831.3,-375.56 864.63,-329.48"/> +<polygon fill="black" stroke="black" points="867.37,-331.67 870.4,-321.52 861.7,-327.57 867.37,-331.67"/> +</g> +<!-- STRUCT_BOT --> +<g id="node25" class="node"> +<title>STRUCT_BOT</title> +<ellipse fill="lightgreen" stroke="black" cx="751.51" cy="-82.75" rx="44.7" ry="18"/> +<text text-anchor="start" x="726.76" y="-78.7" font-family="Times New Roman,serif" font-weight="bold" font-size="14.00">⊥</text> +<text text-anchor="start" x="742.51" y="-78.7" font-family="Times New Roman,serif" font-size="14.00">:struct</text> +</g> +<!-- STRUCT_BOT->BOT --> +<g id="edge43" class="edge"> +<title>STRUCT_BOT->BOT</title> +<path fill="none" stroke="black" d="M725.72,-67.77C709,-58.7 687.2,-46.89 669.97,-37.55"/> +<polygon fill="black" stroke="black" points="671.71,-34.51 661.25,-32.82 668.37,-40.67 671.71,-34.51"/> +</g> +<!-- STRUCT_S1->STRUCT_BOT --> +<g id="edge40" class="edge"> +<title>STRUCT_S1->STRUCT_BOT</title> +<path fill="none" stroke="black" d="M706.86,-264.91C715.3,-230.49 733.97,-154.31 744.29,-112.19"/> +<polygon fill="black" stroke="black" points="747.69,-113.04 746.67,-102.5 740.89,-111.37 747.69,-113.04"/> +</g> +<!-- STRUCT_S1->STRUCT_S2 --> +<!-- STRUCT_S2->STRUCT_BOT --> +<g id="edge41" class="edge"> +<title>STRUCT_S2->STRUCT_BOT</title> +<path fill="none" stroke="black" d="M792.36,-256.52C783.62,-219.3 767.61,-151.25 758.45,-112.26"/> +<polygon fill="black" stroke="black" points="761.88,-111.57 756.18,-102.64 755.07,-113.17 761.88,-111.57"/> +</g> +<!-- STRUCT_S2->STRUCT_SN --> +<!-- STRUCT_SN->STRUCT_BOT --> +<g id="edge42" class="edge"> +<title>STRUCT_SN->STRUCT_BOT</title> +<path fill="none" stroke="black" d="M870.86,-245.05C841.74,-205.46 796.64,-144.13 771.03,-109.3"/> +<polygon fill="black" stroke="black" points="773.99,-107.42 765.25,-101.44 768.36,-111.57 773.99,-107.42"/> +</g> +<!-- MEM_ALIAS1 --> +<g id="node31" class="node"> +<title>MEM_ALIAS1</title> +<ellipse fill="blue" stroke="black" cx="975.51" cy="-282.65" rx="20.13" ry="20.13"/> +<text text-anchor="middle" x="975.51" y="-277.6" font-family="Times New Roman,serif" font-size="14.00" fill="white">#1</text> +</g> +<!-- MEM_TOP->MEM_ALIAS1 --> +<g id="edge47" class="edge"> +<title>MEM_TOP->MEM_ALIAS1</title> +<path fill="none" stroke="black" d="M996.51,-474.51C992.58,-438.66 983.84,-358.73 978.96,-314.18"/> +<polygon fill="black" stroke="black" points="982.45,-313.94 977.89,-304.38 975.5,-314.7 982.45,-313.94"/> +</g> +<!-- MEM_ALIASDOTS --> +<g id="node32" class="node"> +<title>MEM_ALIASDOTS</title> +<ellipse fill="blue" stroke="black" cx="1036.51" cy="-282.65" rx="27" ry="18"/> +<text text-anchor="middle" x="1036.51" y="-277.6" font-family="Times New Roman,serif" font-size="14.00" fill="white">...</text> +</g> +<!-- MEM_TOP->MEM_ALIASDOTS --> +<g id="edge48" class="edge"> +<title>MEM_TOP->MEM_ALIASDOTS</title> +<path fill="none" stroke="black" d="M1001.81,-474.51C1008.41,-438.02 1023.27,-355.86 1031.23,-311.83"/> +<polygon fill="black" stroke="black" points="1034.63,-312.69 1032.97,-302.23 1027.74,-311.45 1034.63,-312.69"/> +</g> +<!-- MEM_ALIASN --> +<g id="node33" class="node"> +<title>MEM_ALIASN</title> +<ellipse fill="blue" stroke="black" cx="1097.51" cy="-282.65" rx="20.13" ry="20.13"/> +<text text-anchor="middle" x="1097.51" y="-277.6" font-family="Times New Roman,serif" font-size="14.00" fill="white">#n</text> +</g> +<!-- MEM_TOP->MEM_ALIASN --> +<g id="edge49" class="edge"> +<title>MEM_TOP->MEM_ALIASN</title> +<path fill="none" stroke="black" d="M1006.95,-474.88C1024.11,-438.46 1063.18,-355.52 1083.95,-311.44"/> +<polygon fill="black" stroke="black" points="1087.07,-313.03 1088.16,-302.49 1080.73,-310.05 1087.07,-313.03"/> +</g> +<!-- MEM_BOT --> +<g id="node30" class="node"> +<title>MEM_BOT</title> +<ellipse fill="blue" stroke="black" cx="998.51" cy="-82.75" rx="43.67" ry="18"/> +<text text-anchor="start" x="974.51" y="-78.7" font-family="Times New Roman,serif" font-weight="bold" font-size="14.00" fill="white">⊥</text> +<text text-anchor="start" x="990.26" y="-78.7" font-family="Times New Roman,serif" font-size="14.00" fill="white">:mem</text> +</g> +<!-- MEM_BOT->BOT --> +<g id="edge53" class="edge"> +<title>MEM_BOT->BOT</title> +<path fill="none" stroke="black" d="M958.6,-75.08C887.17,-63.15 738.86,-38.38 673.56,-27.48"/> +<polygon fill="black" stroke="black" points="674.3,-24.05 663.86,-25.86 673.15,-30.96 674.3,-24.05"/> +</g> +<!-- MEM_ALIAS1->MEM_BOT --> +<g id="edge50" class="edge"> +<title>MEM_ALIAS1->MEM_BOT</title> +<path fill="none" stroke="black" d="M977.84,-262.38C981.92,-226.96 990.35,-153.62 995.09,-112.45"/> +<polygon fill="black" stroke="black" points="998.57,-112.87 996.23,-102.53 991.61,-112.07 998.57,-112.87"/> +</g> +<!-- MEM_ALIAS1->MEM_ALIASDOTS --> +<!-- MEM_ALIASDOTS->MEM_BOT --> +<g id="edge51" class="edge"> +<title>MEM_ALIASDOTS->MEM_BOT</title> +<path fill="none" stroke="black" d="M1033.07,-264.56C1026.49,-229.93 1012.06,-154.01 1004.08,-112.06"/> +<polygon fill="black" stroke="black" points="1007.56,-111.6 1002.25,-102.43 1000.68,-112.91 1007.56,-111.6"/> +</g> +<!-- MEM_ALIASDOTS->MEM_ALIASN --> +<!-- MEM_ALIASN->MEM_BOT --> +<g id="edge52" class="edge"> +<title>MEM_ALIASN->MEM_BOT</title> +<path fill="none" stroke="black" d="M1088.37,-264.2C1070.97,-229.07 1032.98,-152.35 1012.41,-110.82"/> +<polygon fill="black" stroke="black" points="1015.58,-109.34 1008.01,-101.93 1009.31,-112.45 1015.58,-109.34"/> +</g> +<!-- TUPLE1 --> +<g id="node36" class="node"> +<title>TUPLE1</title> +<polygon fill="none" stroke="none" points="1185.51,-309.15 1131.51,-309.15 1131.51,-256.15 1185.51,-256.15 1185.51,-309.15"/> +<polygon fill="pink" stroke="none" points="1139.76,-282.65 1139.76,-305.15 1177.26,-305.15 1177.26,-282.65 1139.76,-282.65"/> +<polygon fill="none" stroke="black" points="1139.76,-282.65 1139.76,-305.15 1177.26,-305.15 1177.26,-282.65 1139.76,-282.65"/> +<text text-anchor="start" x="1142.76" y="-288.85" font-family="Times New Roman,serif" font-size="14.00">Tuple</text> +<polygon fill="black" stroke="none" points="1139.76,-260.15 1139.76,-282.65 1177.26,-282.65 1177.26,-260.15 1139.76,-260.15"/> +<polygon fill="none" stroke="black" points="1139.76,-260.15 1139.76,-282.65 1177.26,-282.65 1177.26,-260.15 1139.76,-260.15"/> +<text text-anchor="start" x="1146.88" y="-266.35" font-family="Times New Roman,serif" font-size="14.00" fill="white">type</text> +</g> +<!-- TUPLE_TOP->TUPLE1 --> +<g id="edge57" class="edge"> +<title>TUPLE_TOP->TUPLE1</title> +<path fill="none" stroke="black" d="M1180.42,-474.51C1176.51,-440.23 1167.99,-365.66 1162.8,-320.24"/> +<polygon fill="black" stroke="black" points="1166.28,-319.86 1161.67,-310.32 1159.33,-320.65 1166.28,-319.86"/> +</g> +<!-- TUPLE2 --> +<g id="node37" class="node"> +<title>TUPLE2</title> +<polygon fill="none" stroke="none" points="1253.51,-320.4 1199.51,-320.4 1199.51,-244.9 1253.51,-244.9 1253.51,-320.4"/> +<polygon fill="pink" stroke="none" points="1207.76,-293.9 1207.76,-316.4 1245.26,-316.4 1245.26,-293.9 1207.76,-293.9"/> +<polygon fill="none" stroke="black" points="1207.76,-293.9 1207.76,-316.4 1245.26,-316.4 1245.26,-293.9 1207.76,-293.9"/> +<text text-anchor="start" x="1210.76" y="-300.1" font-family="Times New Roman,serif" font-size="14.00">Tuple</text> +<polygon fill="black" stroke="none" points="1207.76,-271.4 1207.76,-293.9 1245.26,-293.9 1245.26,-271.4 1207.76,-271.4"/> +<polygon fill="none" stroke="black" points="1207.76,-271.4 1207.76,-293.9 1245.26,-293.9 1245.26,-271.4 1207.76,-271.4"/> +<text text-anchor="start" x="1214.88" y="-277.6" font-family="Times New Roman,serif" font-size="14.00" fill="white">type</text> +<polygon fill="black" stroke="none" points="1207.76,-248.9 1207.76,-271.4 1245.26,-271.4 1245.26,-248.9 1207.76,-248.9"/> +<polygon fill="none" stroke="black" points="1207.76,-248.9 1207.76,-271.4 1245.26,-271.4 1245.26,-248.9 1207.76,-248.9"/> +<text text-anchor="start" x="1214.88" y="-255.1" font-family="Times New Roman,serif" font-size="14.00" fill="white">type</text> +</g> +<!-- TUPLE_TOP->TUPLE2 --> +<g id="edge58" class="edge"> +<title>TUPLE_TOP->TUPLE2</title> +<path fill="none" stroke="black" d="M1186.34,-474.51C1192.95,-442.94 1206.72,-377.19 1216.28,-331.51"/> +<polygon fill="black" stroke="black" points="1219.68,-332.35 1218.3,-321.85 1212.83,-330.92 1219.68,-332.35"/> +</g> +<!-- TUPLEN --> +<g id="node38" class="node"> +<title>TUPLEN</title> +<polygon fill="none" stroke="none" points="1321.51,-331.65 1267.51,-331.65 1267.51,-233.65 1321.51,-233.65 1321.51,-331.65"/> +<polygon fill="pink" stroke="none" points="1275.76,-305.15 1275.76,-327.65 1313.26,-327.65 1313.26,-305.15 1275.76,-305.15"/> +<polygon fill="none" stroke="black" points="1275.76,-305.15 1275.76,-327.65 1313.26,-327.65 1313.26,-305.15 1275.76,-305.15"/> +<text text-anchor="start" x="1278.76" y="-311.35" font-family="Times New Roman,serif" font-size="14.00">Tuple</text> +<polygon fill="black" stroke="none" points="1275.76,-282.65 1275.76,-305.15 1313.26,-305.15 1313.26,-282.65 1275.76,-282.65"/> +<polygon fill="none" stroke="black" points="1275.76,-282.65 1275.76,-305.15 1313.26,-305.15 1313.26,-282.65 1275.76,-282.65"/> +<text text-anchor="start" x="1282.88" y="-288.85" font-family="Times New Roman,serif" font-size="14.00" fill="white">type</text> +<polygon fill="black" stroke="none" points="1275.76,-260.15 1275.76,-282.65 1313.26,-282.65 1313.26,-260.15 1275.76,-260.15"/> +<polygon fill="none" stroke="black" points="1275.76,-260.15 1275.76,-282.65 1313.26,-282.65 1313.26,-260.15 1275.76,-260.15"/> +<text text-anchor="start" x="1288.88" y="-266.35" font-family="Times New Roman,serif" font-size="14.00" fill="white">...</text> +<polygon fill="black" stroke="none" points="1275.76,-237.65 1275.76,-260.15 1313.26,-260.15 1313.26,-237.65 1275.76,-237.65"/> +<polygon fill="none" stroke="black" points="1275.76,-237.65 1275.76,-260.15 1313.26,-260.15 1313.26,-237.65 1275.76,-237.65"/> +<text text-anchor="start" x="1282.88" y="-243.85" font-family="Times New Roman,serif" font-size="14.00" fill="white">type</text> +</g> +<!-- TUPLE_TOP->TUPLEN --> +<g id="edge59" class="edge"> +<title>TUPLE_TOP->TUPLEN</title> +<path fill="none" stroke="black" d="M1192.06,-474.88C1207.65,-445.62 1239.24,-386.36 1263.24,-341.32"/> +<polygon fill="black" stroke="black" points="1266.22,-343.18 1267.83,-332.71 1260.04,-339.88 1266.22,-343.18"/> +</g> +<!-- TUPLE_BOT --> +<g id="node35" class="node"> +<title>TUPLE_BOT</title> +<ellipse fill="pink" stroke="black" cx="1192.51" cy="-82.75" rx="42.65" ry="18"/> +<text text-anchor="start" x="1169.26" y="-78.7" font-family="Times New Roman,serif" font-weight="bold" font-size="14.00">⊥</text> +<text text-anchor="start" x="1185.01" y="-78.7" font-family="Times New Roman,serif" font-size="14.00">:tuple</text> +</g> +<!-- TUPLE_BOT->BOT --> +<g id="edge63" class="edge"> +<title>TUPLE_BOT->BOT</title> +<path fill="none" stroke="black" d="M1151.54,-77.32C1046.53,-65.95 769.32,-35.95 674.14,-25.65"/> +<polygon fill="black" stroke="black" points="674.52,-22.18 664.2,-24.58 673.77,-29.14 674.52,-22.18"/> +</g> +<!-- TUPLE1->TUPLE_BOT --> +<g id="edge60" class="edge"> +<title>TUPLE1->TUPLE_BOT</title> +<path fill="none" stroke="black" d="M1162.95,-256.52C1169.28,-219.3 1180.86,-151.25 1187.49,-112.26"/> +<polygon fill="black" stroke="black" points="1190.9,-113.1 1189.12,-102.66 1184,-111.93 1190.9,-113.1"/> +</g> +<!-- TUPLE2->TUPLE_BOT --> +<g id="edge61" class="edge"> +<title>TUPLE2->TUPLE_BOT</title> +<path fill="none" stroke="black" d="M1220.11,-245.05C1213.55,-206.44 1203.46,-147.16 1197.47,-111.94"/> +<polygon fill="black" stroke="black" points="1200.99,-111.74 1195.86,-102.47 1194.09,-112.92 1200.99,-111.74"/> +</g> +<!-- TUPLEN->TUPLE_BOT --> +<g id="edge62" class="edge"> +<title>TUPLEN->TUPLE_BOT</title> +<path fill="none" stroke="black" d="M1269.56,-233.75C1249.85,-195.12 1223.04,-142.58 1206.8,-110.75"/> +<polygon fill="black" stroke="black" points="1210.07,-109.46 1202.41,-102.15 1203.83,-112.65 1210.07,-109.46"/> +</g> +</g> +</svg> diff --git a/docs/chapter24/lattice2.gv b/docs/chapter24/lattice2.gv new file mode 100644 index 00000000..6aa37fa0 --- /dev/null +++ b/docs/chapter24/lattice2.gv @@ -0,0 +1,85 @@ +digraph Lattice { + compound = true; + // Define nodes + splines=false; + node [shape=oval, style=filled]; + nodesep=0.2; + ranksep=0.4; + + TOP [label="~scalar\n+int+tmp+0", fillcolor=black, fontcolor=white, group=center]; + + // ------------------------ + PTRHQ [label="~tmp\n+tmp+0", fillcolor=green, fontcolor=white, group=left]; + TOP -> PTRHQ + + VALH_ [label="~nscalar\n+int+tmp", fillcolor=white, group=center]; + TOP -> VALH_ + + INTHQ [label="~int\n+int+0", fillcolor=lightblue, group=right]; + TOP -> INTHQ + + LEFTHI [label="junk", style=invis, group=junkleft] + + + PTRHQ -> LEFTHI-> VALH_ -> INTHQ [style=invis]; + { rank=same; PTRHQ; LEFTHI; VALH_; INTHQ } + + // ------------------------ + PTRH_ [label="~ntmp\n+tmp", fillcolor=green, fontcolor=white, group=left]; + VALH_ -> PTRH_ + PTRHQ -> PTRH_ + + INTH_ [label="~nint\n+int", fillcolor=lightblue, group=right]; + VALH_ -> INTH_ + INTHQ -> INTH_ + { rank=same; PTRH_; INTH_ } + + // ------------------------ + NILX_ [label="~nil\n[int,tmp]+0", fillcolor=aqua, group=junkleft]; + INTHQ -> NILX_ + PTRHQ -> NILX_ + + NIL__ [label="nil\n[+int+tmp],0", fillcolor=pink]; + VALH_ -> NIL__; + + NILX_ -> NIL__ [style=invis]; + { rank=same; NIL__; NILX_ } + + // ------------------------ + PTRL_ [label="ntmp\ntmp", fillcolor=green, fontcolor=white, group=left]; + PTRH_ -> PTRL_ + + INTL_ [label="nint\nint", fillcolor=lightblue, group=right]; + INTH_ -> INTL_ + { rank=same; PTRL_; INTL_ } + + // ------------------------ + PTRL0 [label="tmp\ntmp,0", fillcolor=green, fontcolor=white, group=left]; + PTRL_ -> PTRL0 + NIL__ -> PTRL0 + + VALL_ [label="nscalar\nint,tmp", fillcolor=white, group=center]; + PTRL_ -> VALL_ + INTL_ -> VALL_ + NILX_ -> VALL_ + + INTL0 [label="int\nint,0", fillcolor=lightblue, group=right]; + INTL_ -> INTL0 + NIL__ -> INTL0 + + PTRL0 -> VALL_ -> INTL0 [style=invis]; + { rank=same; PTRL0; VALL_; INTL0 } + + // ------------------------ + BOT [label="scalar\nint,tmp,0", fillcolor=black, fontcolor=white, group=center]; + PTRL0 -> BOT + INTL0 -> BOT + VALL_ -> BOT + + // ------------------------ + // Verticle alignment + TOP -> VALH_ -> VALL_ -> BOT [style=invis]; + PTRHQ -> PTRH_ -> PTRL_ -> PTRL0 [style=invis]; + INTHQ -> INTH_ -> INTL_ -> INTL0 [style=invis]; + LEFTHI -> NILX_ [style=invis] +} diff --git a/docs/chapter24/lattice2.svg b/docs/chapter24/lattice2.svg new file mode 100644 index 00000000..8b682aa7 --- /dev/null +++ b/docs/chapter24/lattice2.svg @@ -0,0 +1,260 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" + "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<!-- Generated by graphviz version 12.2.0 (20241103.1931) + --> +<!-- Title: Lattice Pages: 1 --> +<svg width="478pt" height="501pt" + viewBox="0.00 0.00 477.96 500.90" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> +<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 496.9)"> +<title>Lattice</title> +<polygon fill="white" stroke="none" points="-4,4 -4,-496.9 473.96,-496.9 473.96,4 -4,4"/> +<!-- TOP --> +<g id="node1" class="node"> +<title>TOP</title> +<ellipse fill="black" stroke="black" cx="240.13" cy="-463.91" rx="59.04" ry="28.99"/> +<text text-anchor="middle" x="240.13" y="-467.11" font-family="Times New Roman,serif" font-size="14.00" fill="white">~scalar</text> +<text text-anchor="middle" x="240.13" y="-450.61" font-family="Times New Roman,serif" font-size="14.00" fill="white">+int+tmp+0</text> +</g> +<!-- PTRHQ --> +<g id="node2" class="node"> +<title>PTRHQ</title> +<ellipse fill="green" stroke="black" cx="43.13" cy="-376.92" rx="43.13" ry="28.99"/> +<text text-anchor="middle" x="43.13" y="-380.12" font-family="Times New Roman,serif" font-size="14.00" fill="white">~tmp</text> +<text text-anchor="middle" x="43.13" y="-363.62" font-family="Times New Roman,serif" font-size="14.00" fill="white">+tmp+0</text> +</g> +<!-- TOP->PTRHQ --> +<g id="edge1" class="edge"> +<title>TOP->PTRHQ</title> +<path fill="none" stroke="black" d="M196.41,-444.04C164.74,-430.38 121.99,-411.94 89.68,-398"/> +<polygon fill="black" stroke="black" points="91.11,-394.81 80.55,-394.06 88.34,-401.24 91.11,-394.81"/> +</g> +<!-- VALH_ --> +<g id="node3" class="node"> +<title>VALH_</title> +<ellipse fill="white" stroke="black" cx="240.13" cy="-376.92" rx="48.44" ry="28.99"/> +<text text-anchor="middle" x="240.13" y="-380.12" font-family="Times New Roman,serif" font-size="14.00">~nscalar</text> +<text text-anchor="middle" x="240.13" y="-363.62" font-family="Times New Roman,serif" font-size="14.00">+int+tmp</text> +</g> +<!-- TOP->VALH_ --> +<g id="edge2" class="edge"> +<title>TOP->VALH_</title> +<path fill="none" stroke="black" d="M235.15,-434.61C234.93,-429.02 234.85,-423.06 234.9,-417.18"/> +<polygon fill="black" stroke="black" points="238.39,-417.69 235.12,-407.61 231.39,-417.52 238.39,-417.69"/> +</g> +<!-- TOP->VALH_ --> +<!-- INTHQ --> +<g id="node4" class="node"> +<title>INTHQ</title> +<ellipse fill="lightblue" stroke="black" cx="432.13" cy="-376.92" rx="37.83" ry="28.99"/> +<text text-anchor="middle" x="432.13" y="-380.12" font-family="Times New Roman,serif" font-size="14.00">~int</text> +<text text-anchor="middle" x="432.13" y="-363.62" font-family="Times New Roman,serif" font-size="14.00">+int+0</text> +</g> +<!-- TOP->INTHQ --> +<g id="edge3" class="edge"> +<title>TOP->INTHQ</title> +<path fill="none" stroke="black" d="M283.22,-443.83C314.91,-429.81 357.78,-410.83 389.39,-396.84"/> +<polygon fill="black" stroke="black" points="390.53,-400.16 398.26,-392.92 387.7,-393.76 390.53,-400.16"/> +</g> +<!-- LEFTHI --> +<!-- PTRHQ->LEFTHI --> +<!-- PTRH_ --> +<g id="node6" class="node"> +<title>PTRH_</title> +<ellipse fill="green" stroke="black" cx="43.13" cy="-289.94" rx="36.77" ry="28.99"/> +<text text-anchor="middle" x="43.13" y="-293.14" font-family="Times New Roman,serif" font-size="14.00" fill="white">~ntmp</text> +<text text-anchor="middle" x="43.13" y="-276.64" font-family="Times New Roman,serif" font-size="14.00" fill="white">+tmp</text> +</g> +<!-- PTRHQ->PTRH_ --> +<g id="edge8" class="edge"> +<title>PTRHQ->PTRH_</title> +<path fill="none" stroke="black" d="M38.15,-347.62C37.93,-342.03 37.85,-336.07 37.9,-330.2"/> +<polygon fill="black" stroke="black" points="41.39,-330.71 38.12,-320.63 34.39,-330.54 41.39,-330.71"/> +</g> +<!-- PTRHQ->PTRH_ --> +<!-- NILX_ --> +<g id="node8" class="node"> +<title>NILX_</title> +<ellipse fill="aqua" stroke="black" cx="150.13" cy="-289.94" rx="56.39" ry="28.99"/> +<text text-anchor="middle" x="150.13" y="-293.14" font-family="Times New Roman,serif" font-size="14.00">~nil</text> +<text text-anchor="middle" x="150.13" y="-276.64" font-family="Times New Roman,serif" font-size="14.00">[int,tmp]+0</text> +</g> +<!-- PTRHQ->NILX_ --> +<g id="edge12" class="edge"> +<title>PTRHQ->NILX_</title> +<path fill="none" stroke="black" d="M70.41,-354.26C82.91,-344.33 97.94,-332.4 111.56,-321.58"/> +<polygon fill="black" stroke="black" points="113.43,-324.56 119.09,-315.6 109.08,-319.08 113.43,-324.56"/> +</g> +<!-- VALH_->INTHQ --> +<!-- VALH_->PTRH_ --> +<g id="edge7" class="edge"> +<title>VALH_->PTRH_</title> +<path fill="none" stroke="black" d="M201.21,-359.13C167.78,-344.71 119.68,-323.96 85.33,-309.14"/> +<polygon fill="black" stroke="black" points="87.1,-306.09 76.53,-305.35 84.33,-312.52 87.1,-306.09"/> +</g> +<!-- INTH_ --> +<g id="node7" class="node"> +<title>INTH_</title> +<ellipse fill="lightblue" stroke="black" cx="432.13" cy="-289.94" rx="31.47" ry="28.99"/> +<text text-anchor="middle" x="432.13" y="-293.14" font-family="Times New Roman,serif" font-size="14.00">~nint</text> +<text text-anchor="middle" x="432.13" y="-276.64" font-family="Times New Roman,serif" font-size="14.00">+int</text> +</g> +<!-- VALH_->INTH_ --> +<g id="edge9" class="edge"> +<title>VALH_->INTH_</title> +<path fill="none" stroke="black" d="M278.53,-358.93C311.9,-344.16 360.02,-322.86 393.48,-308.05"/> +<polygon fill="black" stroke="black" points="394.67,-311.35 402.4,-304.1 391.84,-304.95 394.67,-311.35"/> +</g> +<!-- NIL__ --> +<g id="node9" class="node"> +<title>NIL__</title> +<ellipse fill="pink" stroke="black" cx="324.13" cy="-289.94" rx="62.23" ry="28.99"/> +<text text-anchor="middle" x="324.13" y="-293.14" font-family="Times New Roman,serif" font-size="14.00">nil</text> +<text text-anchor="middle" x="324.13" y="-276.64" font-family="Times New Roman,serif" font-size="14.00">[+int+tmp],0</text> +</g> +<!-- VALH_->NIL__ --> +<g id="edge13" class="edge"> +<title>VALH_->NIL__</title> +<path fill="none" stroke="black" d="M264.43,-351.34C272.67,-343.01 282.01,-333.55 290.83,-324.64"/> +<polygon fill="black" stroke="black" points="293.12,-327.3 297.66,-317.72 288.14,-322.38 293.12,-327.3"/> +</g> +<!-- VALL_ --> +<g id="node13" class="node"> +<title>VALL_</title> +<ellipse fill="white" stroke="black" cx="240.13" cy="-115.97" rx="39.42" ry="28.99"/> +<text text-anchor="middle" x="240.13" y="-119.17" font-family="Times New Roman,serif" font-size="14.00">nscalar</text> +<text text-anchor="middle" x="240.13" y="-102.67" font-family="Times New Roman,serif" font-size="14.00">int,tmp</text> +</g> +<!-- VALH_->VALL_ --> +<!-- INTHQ->INTH_ --> +<g id="edge10" class="edge"> +<title>INTHQ->INTH_</title> +<path fill="none" stroke="black" d="M427.17,-348.1C426.94,-342.37 426.85,-336.25 426.9,-330.21"/> +<polygon fill="black" stroke="black" points="430.39,-330.42 427.13,-320.34 423.39,-330.26 430.39,-330.42"/> +</g> +<!-- INTHQ->INTH_ --> +<!-- INTHQ->NILX_ --> +<g id="edge11" class="edge"> +<title>INTHQ->NILX_</title> +<path fill="none" stroke="black" d="M396.99,-365.33C350,-351.17 266.03,-325.87 209.23,-308.75"/> +<polygon fill="black" stroke="black" points="210.28,-305.41 199.69,-305.88 208.26,-312.11 210.28,-305.41"/> +</g> +<!-- LEFTHI->VALH_ --> +<!-- LEFTHI->NILX_ --> +<!-- PTRL_ --> +<g id="node10" class="node"> +<title>PTRL_</title> +<ellipse fill="green" stroke="black" cx="43.13" cy="-202.96" rx="31.47" ry="28.99"/> +<text text-anchor="middle" x="43.13" y="-206.16" font-family="Times New Roman,serif" font-size="14.00" fill="white">ntmp</text> +<text text-anchor="middle" x="43.13" y="-189.66" font-family="Times New Roman,serif" font-size="14.00" fill="white">tmp</text> +</g> +<!-- PTRH_->PTRL_ --> +<g id="edge15" class="edge"> +<title>PTRH_->PTRL_</title> +<path fill="none" stroke="black" d="M38.17,-261.11C37.94,-255.39 37.85,-249.26 37.9,-243.22"/> +<polygon fill="black" stroke="black" points="41.39,-243.44 38.13,-233.36 34.39,-243.27 41.39,-243.44"/> +</g> +<!-- PTRH_->PTRL_ --> +<!-- INTL_ --> +<g id="node11" class="node"> +<title>INTL_</title> +<ellipse fill="lightblue" stroke="black" cx="432.13" cy="-202.96" rx="27" ry="28.99"/> +<text text-anchor="middle" x="432.13" y="-206.16" font-family="Times New Roman,serif" font-size="14.00">nint</text> +<text text-anchor="middle" x="432.13" y="-189.66" font-family="Times New Roman,serif" font-size="14.00">int</text> +</g> +<!-- INTH_->INTL_ --> +<g id="edge16" class="edge"> +<title>INTH_->INTL_</title> +<path fill="none" stroke="black" d="M427.17,-261.11C426.94,-255.39 426.85,-249.26 426.9,-243.22"/> +<polygon fill="black" stroke="black" points="430.39,-243.44 427.13,-233.36 423.39,-243.27 430.39,-243.44"/> +</g> +<!-- INTH_->INTL_ --> +<!-- NILX_->NIL__ --> +<!-- NILX_->VALL_ --> +<g id="edge21" class="edge"> +<title>NILX_->VALL_</title> +<path fill="none" stroke="black" d="M164.79,-261.6C180.03,-232.15 203.95,-185.91 220.74,-153.45"/> +<polygon fill="black" stroke="black" points="223.74,-155.27 225.23,-144.78 217.53,-152.06 223.74,-155.27"/> +</g> +<!-- PTRL0 --> +<g id="node12" class="node"> +<title>PTRL0</title> +<ellipse fill="green" stroke="black" cx="43.13" cy="-115.97" rx="34.12" ry="28.99"/> +<text text-anchor="middle" x="43.13" y="-119.17" font-family="Times New Roman,serif" font-size="14.00" fill="white">tmp</text> +<text text-anchor="middle" x="43.13" y="-102.67" font-family="Times New Roman,serif" font-size="14.00" fill="white">tmp,0</text> +</g> +<!-- NIL__->PTRL0 --> +<g id="edge18" class="edge"> +<title>NIL__->PTRL0</title> +<path fill="none" stroke="black" d="M286.24,-266.48C232.36,-233.13 134.24,-172.38 80.6,-139.17"/> +<polygon fill="black" stroke="black" points="82.76,-136.39 72.41,-134.1 79.07,-142.34 82.76,-136.39"/> +</g> +<!-- INTL0 --> +<g id="node14" class="node"> +<title>INTL0</title> +<ellipse fill="lightblue" stroke="black" cx="432.13" cy="-115.97" rx="28.81" ry="28.99"/> +<text text-anchor="middle" x="432.13" y="-119.17" font-family="Times New Roman,serif" font-size="14.00">int</text> +<text text-anchor="middle" x="432.13" y="-102.67" font-family="Times New Roman,serif" font-size="14.00">int,0</text> +</g> +<!-- NIL__->INTL0 --> +<g id="edge23" class="edge"> +<title>NIL__->INTL0</title> +<path fill="none" stroke="black" d="M341.49,-261.99C360.34,-231.61 390.49,-183.05 410.79,-150.35"/> +<polygon fill="black" stroke="black" points="413.65,-152.38 415.95,-142.04 407.7,-148.69 413.65,-152.38"/> +</g> +<!-- PTRL_->PTRL0 --> +<g id="edge17" class="edge"> +<title>PTRL_->PTRL0</title> +<path fill="none" stroke="black" d="M38.17,-174.13C37.94,-168.47 37.85,-162.41 37.9,-156.43"/> +<polygon fill="black" stroke="black" points="41.39,-156.75 38.12,-146.67 34.39,-156.58 41.39,-156.75"/> +</g> +<!-- PTRL_->PTRL0 --> +<!-- PTRL_->VALL_ --> +<g id="edge19" class="edge"> +<title>PTRL_->VALL_</title> +<path fill="none" stroke="black" d="M71.36,-189.78C103.94,-175.73 157.92,-152.44 196.04,-135.99"/> +<polygon fill="black" stroke="black" points="197.16,-139.32 204.96,-132.15 194.39,-132.9 197.16,-139.32"/> +</g> +<!-- INTL_->VALL_ --> +<g id="edge20" class="edge"> +<title>INTL_->VALL_</title> +<path fill="none" stroke="black" d="M407.43,-191.02C376.23,-177.21 322.01,-153.22 283.77,-136.29"/> +<polygon fill="black" stroke="black" points="285.39,-133.18 274.83,-132.33 282.55,-139.58 285.39,-133.18"/> +</g> +<!-- INTL_->INTL0 --> +<g id="edge22" class="edge"> +<title>INTL_->INTL0</title> +<path fill="none" stroke="black" d="M427.17,-174.13C426.94,-168.41 426.85,-162.28 426.9,-156.24"/> +<polygon fill="black" stroke="black" points="430.39,-156.46 427.13,-146.38 423.39,-156.29 430.39,-156.46"/> +</g> +<!-- INTL_->INTL0 --> +<!-- PTRL0->VALL_ --> +<!-- BOT --> +<g id="node15" class="node"> +<title>BOT</title> +<ellipse fill="black" stroke="black" cx="240.13" cy="-28.99" rx="46.85" ry="28.99"/> +<text text-anchor="middle" x="240.13" y="-32.19" font-family="Times New Roman,serif" font-size="14.00" fill="white">scalar</text> +<text text-anchor="middle" x="240.13" y="-15.69" font-family="Times New Roman,serif" font-size="14.00" fill="white">int,tmp,0</text> +</g> +<!-- PTRL0->BOT --> +<g id="edge26" class="edge"> +<title>PTRL0->BOT</title> +<path fill="none" stroke="black" d="M73.48,-101.88C105.02,-88.28 154.83,-66.79 191.79,-50.85"/> +<polygon fill="black" stroke="black" points="193.14,-54.08 200.94,-46.9 190.37,-47.65 193.14,-54.08"/> +</g> +<!-- VALL_->INTL0 --> +<!-- VALL_->BOT --> +<g id="edge28" class="edge"> +<title>VALL_->BOT</title> +<path fill="none" stroke="black" d="M235.17,-87.15C234.94,-81.48 234.85,-75.42 234.9,-69.44"/> +<polygon fill="black" stroke="black" points="238.39,-69.76 235.12,-59.68 231.39,-69.6 238.39,-69.76"/> +</g> +<!-- VALL_->BOT --> +<!-- INTL0->BOT --> +<g id="edge27" class="edge"> +<title>INTL0->BOT</title> +<path fill="none" stroke="black" d="M405.84,-103.34C375.52,-89.91 325.06,-67.58 287.78,-51.08"/> +<polygon fill="black" stroke="black" points="289.59,-48.05 279.03,-47.21 286.75,-54.45 289.59,-48.05"/> +</g> +</g> +</svg> diff --git a/docs/chapter24/pardoe.docx b/docs/chapter24/pardoe.docx Binary files differnew file mode 100644 index 00000000..24fde921 --- /dev/null +++ b/docs/chapter24/pardoe.docx diff --git a/docs/chapter24/webtcp.min.js b/docs/chapter24/webtcp.min.js new file mode 100644 index 00000000..bf23ee5a --- /dev/null +++ b/docs/chapter24/webtcp.min.js @@ -0,0 +1,65 @@ +function Http(j){this.cID=Math.random().toString(36).substr(2);this.webtcp=j;this.webtcp.httpClients[this.cID]=this;this.createPacket=function(){return{cID:this.cID,type:"http",host:this.remoteAddress,port:this.remotePort,method:null,data:null}};this.ondata=function(){};this.get=function(g,c){this.on("data",c);this.rpc("httpGet",[g])};this.post=function(g,c,j){this.on("data",j);this.rpc("httpPost",[g,c])}}Http.prototype=new WebTCPIO;function Socket(j,g,c,p){this.sID=Math.random().toString(36).substr(2);this.webtcp=j;this.closed=this.ready=!1;this.options=p;this.sockOpts={_updating:!1};this.remoteAddress=g;this.remotePort=c;this.webtcp.sockets[this.sID]=this;this.createPacket=function(){return{id:Math.random().toString(36).substr(2),sID:this.sID,type:"tcp",options:this.options,host:this.remoteAddress,port:this.remotePort,data:null}};this.onconnect=function(){this.webtcp.sockets[sID].ready=!0;this.webtcp.sockets[sID].closed=!1}; +this.ondata=function(){};this.onend=function(){};this.ontimeout=function(){};this.ondrain=function(){};this.onclose=function(){this.webtcp.sockets[sID].ready=!1;this.webtcp.sockets[sID].closed=!0};this.getSockOpts=function(){this.sockOpts._updating=!0;this.rpc("getSockOpts")};this.onSockOptsRcv=function(c){this.sockOpts=c;this.sockOpts._updating=!1}}Socket.prototype=new WebTCPIO;var JSON;JSON||(JSON={}); +(function(){function j(c,p){var q,t,n,x,i=k,e,l=p[c];l&&"object"==typeof l&&"function"==typeof l.toJSON&&(l=l.toJSON(c));"function"==typeof r&&(l=r.call(p,c,l));switch(typeof l){case "string":return g(l);case "number":return isFinite(l)?String(l):"null";case "boolean":case "null":return String(l);case "object":if(!l)return"null";k+=v;e=[];if("[object Array]"===Object.prototype.toString.apply(l)){x=l.length;for(q=0;q<x;q+=1)e[q]=j(q,l)||"null";n=0===e.length?"[]":k?"[\n"+k+e.join(",\n"+k)+"\n"+i+"]": +"["+e.join(",")+"]";k=i;return n}if(r&&"object"==typeof r){x=r.length;for(q=0;q<x;q+=1)"string"==typeof r[q]&&(t=r[q],n=j(t,l),n&&e.push(g(t)+(k?": ":":")+n))}else for(t in l)Object.prototype.hasOwnProperty.call(l,t)&&(n=j(t,l),n&&e.push(g(t)+(k?": ":":")+n));n=0===e.length?"{}":k?"{\n"+k+e.join(",\n"+k)+"\n"+i+"}":"{"+e.join(",")+"}";k=i;return n}}function g(c){n.lastIndex=0;return n.test(c)?'"'+c.replace(n,function(c){var g=D[c];return"string"==typeof g?g:"\\u"+("0000"+c.charCodeAt(0).toString(16)).slice(-4)})+ +'"':'"'+c+'"'}function c(c){return 10>c?"0"+c:c}"use strict";"function"!=typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+c(this.getUTCMonth()+1)+"-"+c(this.getUTCDate())+"T"+c(this.getUTCHours())+":"+c(this.getUTCMinutes())+":"+c(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var p=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, +n=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,k,v,D={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},r;"function"!=typeof JSON.stringify&&(JSON.stringify=function(c,g,p){var n;v=k="";if("number"==typeof p)for(n=0;n<p;n+=1)v+=" ";else"string"==typeof p&&(v=p);r=g;if(!g||"function"==typeof g||"object"==typeof g&&"number"==typeof g.length)return j("",{"":c});throw Error("JSON.stringify");});"function"!= +typeof JSON.parse&&(JSON.parse=function(c,g){function j(c,k){var i,e,l=c[k];if(l&&"object"==typeof l)for(i in l)Object.prototype.hasOwnProperty.call(l,i)&&(e=j(l,i),void 0!==e?l[i]=e:delete l[i]);return g.call(c,k,l)}var k,c=String(c);p.lastIndex=0;p.test(c)&&(c=c.replace(p,function(c){return"\\u"+("0000"+c.charCodeAt(0).toString(16)).slice(-4)}));if(/^[\],:{}\s]*$/.test(c.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, +"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return k=eval("("+c+")"),"function"==typeof g?j({"":k},""):k;throw new SyntaxError("JSON.parse");})})(); +SockJS=function(){var j=document,g=window,c={},p=function(){};p.prototype.addEventListener=function(a,b){this._listeners||(this._listeners={});a in this._listeners||(this._listeners[a]=[]);var f=this._listeners[a];-1===c.arrIndexOf(f,b)&&f.push(b)};p.prototype.removeEventListener=function(a,b){if(this._listeners&&a in this._listeners){var f=this._listeners[a],d=c.arrIndexOf(f,b);-1!==d&&(1<f.length?this._listeners[a]=f.slice(0,d).concat(f.slice(d+1)):delete this._listeners[a])}};p.prototype.dispatchEvent= +function(a){var b=a.type,c=Array.prototype.slice.call(arguments,0);this["on"+b]&&this["on"+b].apply(this,c);if(this._listeners&&b in this._listeners)for(var d=0;d<this._listeners[b].length;d++)this._listeners[b][d].apply(this,c)};var n=function(a,b){this.type=a;if("undefined"!=typeof b)for(var c in b)b.hasOwnProperty(c)&&(this[c]=b[c])};n.prototype.toString=function(){var a=[],b;for(b in this)if(this.hasOwnProperty(b)){var c=this[b];"function"==typeof c&&(c="[function]");a.push(b+"="+c)}return"SimpleEvent("+ +a.join(", ")+")"};var k=function(a){this.events=a||[]};k.prototype.emit=function(a){var b=Array.prototype.slice.call(arguments,1);!this.nuked&&this["on"+a]&&this["on"+a].apply(this,b);-1===c.arrIndexOf(this.events,a)&&c.log("Event "+JSON.stringify(a)+" not listed "+JSON.stringify(this.events)+" in "+this)};k.prototype.nuke=function(){this.nuked=!0;for(var a=0;a<this.events.length;a++)delete this[this.events[a]]};c.random_string=function(a,b){var b=b||37,c,d=[];for(c=0;c<a;c++)d.push("abcdefghijklmnopqrstuvwxyz0123456789_".substr(Math.floor(Math.random()* +b),1));return d.join("")};c.random_number=function(a){return Math.floor(Math.random()*a)};c.random_number_string=function(a){var b=(""+(a-1)).length;return(Array(b+1).join("0")+c.random_number(a)).slice(-b)};c.getOrigin=function(a){return(a+"/").split("/").slice(0,3).join("/")};c.isSameOriginUrl=function(a,b){return b||(b=g.location.href),a.split("/").slice(0,3).join("/")===b.split("/").slice(0,3).join("/")};c.getParentDomain=function(a){return/^[0-9.]*$/.test(a)||/^\[/.test(a)||!/[.]/.test(a)?a: +a.split(".").slice(1).join(".")};c.objectExtend=function(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a};c.polluteGlobalNamespace=function(){"_jp"in g||(g._jp={})};c.closeFrame=function(a,b){return"c"+JSON.stringify([a,b])};c.userSetCode=function(a){return 1E3===a||3E3<=a&&4999>=a};c.countRTO=function(a){var b;return 100<a?b=3*a:b=a+200,b};c.log=function(){g.console&&console.log&&console.log.apply&&console.log.apply(console,arguments)};c.bind=function(a,b){return a.bind?a.bind(b):function(){return a.apply(b, +arguments)}};c.flatUrl=function(a){return-1===a.indexOf("?")&&-1===a.indexOf("#")};c.amendUrl=function(a){var b=j.location;if(!a)throw Error("Wrong url for SockJS");if(!c.flatUrl(a))throw Error("Only basic urls are supported in SockJS");return 0===a.indexOf("//")&&(a=b.protocol+a),0===a.indexOf("/")&&(a=b.protocol+"//"+b.host+a),a=a.replace(/[/]+$/,""),a};c.arrIndexOf=function(a,b){for(var c=0;c<a.length;c++)if(a[c]===b)return c;return-1};c.arrSkip=function(a,b){var f=c.arrIndexOf(a,b);return-1=== +f?a.slice():a.slice(0,f).concat(a.slice(f+1))};c.isArray=Array.isArray||function(a){return 0<={}.toString.call(a).indexOf("Array")};c.delay=function(a,b){return"function"==typeof a&&(b=a,a=0),setTimeout(b,a)};var v=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,D={"\x00":"\\u0000","\u0001":"\\u0001","\u0002":"\\u0002","\u0003":"\\u0003","\u0004":"\\u0004","\u0005":"\\u0005","\u0006":"\\u0006","\u0007":"\\u0007","\b":"\\b", +"\t":"\\t","\n":"\\n","\x0B":"\\u000b","\f":"\\f","\r":"\\r","\u000e":"\\u000e","\u000f":"\\u000f","\u0010":"\\u0010","\u0011":"\\u0011","\u0012":"\\u0012","\u0013":"\\u0013","\u0014":"\\u0014","\u0015":"\\u0015","\u0016":"\\u0016","\u0017":"\\u0017","\u0018":"\\u0018","\u0019":"\\u0019","\u001a":"\\u001a","\u001b":"\\u001b","\u001c":"\\u001c","\u001d":"\\u001d","\u001e":"\\u001e","\u001f":"\\u001f",'"':'\\"',"\\":"\\\\","\u007f":"\\u007f","\u0080":"\\u0080","\u0081":"\\u0081","\u0082":"\\u0082", +"\u0083":"\\u0083","\u0084":"\\u0084","\u0085":"\\u0085","\u0086":"\\u0086","\u0087":"\\u0087","\u0088":"\\u0088","\u0089":"\\u0089","\u008a":"\\u008a","\u008b":"\\u008b","\u008c":"\\u008c","\u008d":"\\u008d","\u008e":"\\u008e","\u008f":"\\u008f","\u0090":"\\u0090","\u0091":"\\u0091","\u0092":"\\u0092","\u0093":"\\u0093","\u0094":"\\u0094","\u0095":"\\u0095","\u0096":"\\u0096","\u0097":"\\u0097","\u0098":"\\u0098","\u0099":"\\u0099","\u009a":"\\u009a","\u009b":"\\u009b","\u009c":"\\u009c","\u009d":"\\u009d", +"\u009e":"\\u009e","\u009f":"\\u009f","\u00ad":"\\u00ad","\u0600":"\\u0600","\u0601":"\\u0601","\u0602":"\\u0602","\u0603":"\\u0603","\u0604":"\\u0604","\u070f":"\\u070f","\u17b4":"\\u17b4","\u17b5":"\\u17b5","\u200c":"\\u200c","\u200d":"\\u200d","\u200e":"\\u200e","\u200f":"\\u200f","\u2028":"\\u2028","\u2029":"\\u2029","\u202a":"\\u202a","\u202b":"\\u202b","\u202c":"\\u202c","\u202d":"\\u202d","\u202e":"\\u202e","\u202f":"\\u202f","\u2060":"\\u2060","\u2061":"\\u2061","\u2062":"\\u2062","\u2063":"\\u2063", +"\u2064":"\\u2064","\u2065":"\\u2065","\u2066":"\\u2066","\u2067":"\\u2067","\u2068":"\\u2068","\u2069":"\\u2069","\u206a":"\\u206a","\u206b":"\\u206b","\u206c":"\\u206c","\u206d":"\\u206d","\u206e":"\\u206e","\u206f":"\\u206f","\ufeff":"\\ufeff","\ufff0":"\\ufff0","\ufff1":"\\ufff1","\ufff2":"\\ufff2","\ufff3":"\\ufff3","\ufff4":"\\ufff4","\ufff5":"\\ufff5","\ufff6":"\\ufff6","\ufff7":"\\ufff7","\ufff8":"\\ufff8","\ufff9":"\\ufff9","\ufffa":"\\ufffa","\ufffb":"\\ufffb","\ufffc":"\\ufffc","\ufffd":"\\ufffd", +"\ufffe":"\\ufffe","\uffff":"\\uffff"},r=/[\x00-\x1f\ud800-\udfff\ufffe\uffff\u0300-\u0333\u033d-\u0346\u034a-\u034c\u0350-\u0352\u0357-\u0358\u035c-\u0362\u0374\u037e\u0387\u0591-\u05af\u05c4\u0610-\u0617\u0653-\u0654\u0657-\u065b\u065d-\u065e\u06df-\u06e2\u06eb-\u06ec\u0730\u0732-\u0733\u0735-\u0736\u073a\u073d\u073f-\u0741\u0743\u0745\u0747\u07eb-\u07f1\u0951\u0958-\u095f\u09dc-\u09dd\u09df\u0a33\u0a36\u0a59-\u0a5b\u0a5e\u0b5c-\u0b5d\u0e38-\u0e39\u0f43\u0f4d\u0f52\u0f57\u0f5c\u0f69\u0f72-\u0f76\u0f78\u0f80-\u0f83\u0f93\u0f9d\u0fa2\u0fa7\u0fac\u0fb9\u1939-\u193a\u1a17\u1b6b\u1cda-\u1cdb\u1dc0-\u1dcf\u1dfc\u1dfe\u1f71\u1f73\u1f75\u1f77\u1f79\u1f7b\u1f7d\u1fbb\u1fbe\u1fc9\u1fcb\u1fd3\u1fdb\u1fe3\u1feb\u1fee-\u1fef\u1ff9\u1ffb\u1ffd\u2000-\u2001\u20d0-\u20d1\u20d4-\u20d7\u20e7-\u20e9\u2126\u212a-\u212b\u2329-\u232a\u2adc\u302b-\u302c\uaab2-\uaab3\uf900-\ufa0d\ufa10\ufa12\ufa15-\ufa1e\ufa20\ufa22\ufa25-\ufa26\ufa2a-\ufa2d\ufa30-\ufa6d\ufa70-\ufad9\ufb1d\ufb1f\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufb4e\ufff0-\uffff]/g, +B,M=JSON&&JSON.stringify||function(a){return v.lastIndex=0,v.test(a)&&(a=a.replace(v,function(a){return D[a]})),'"'+a+'"'};c.quote=function(a){a=M(a);r.lastIndex=0;if(r.test(a)){if(!B){var b,c={},d=[];for(b=0;65536>b;b++)d.push(String.fromCharCode(b));B=(r.lastIndex=0,d.join("").replace(r,function(a){return c[a]="\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4),""}),r.lastIndex=0,c)}a=a.replace(r,function(a){return B[a]})}return a};var q="websocket xdr-streaming xhr-streaming iframe-eventsource iframe-htmlfile xdr-polling xhr-polling iframe-xhr-polling jsonp-polling".split(" "); +c.probeProtocols=function(){for(var a={},b=0;b<q.length;b++){var c=q[b];a[c]=e[c]&&e[c].enabled()}return a};c.detectProtocols=function(a,b,c){var d={},h=[];b||(b=q);for(var m=0;m<b.length;m++){var g=b[m];d[g]=a[g]}var e=function(a){var b=a.shift();d[b]?h.push(b):0<a.length&&e(a)};return!1!==c.websocket&&e(["websocket"]),d["xhr-streaming"]&&!c.null_origin?h.push("xhr-streaming"):d["xdr-streaming"]&&!c.cookie_needed&&!c.null_origin?h.push("xdr-streaming"):e(["iframe-eventsource","iframe-htmlfile"]), +d["xhr-polling"]&&!c.null_origin?h.push("xhr-polling"):d["xdr-polling"]&&!c.cookie_needed&&!c.null_origin?h.push("xdr-polling"):e(["iframe-xhr-polling","jsonp-polling"]),h};c.createHook=function(){var a="a"+c.random_string(8);if(!("_sockjs_global"in g)){var b={};g._sockjs_global=function(a){return a in b||(b[a]={id:a,del:function(){delete b[a]}}),b[a]}}return g._sockjs_global(a)};c.attachMessage=function(a){c.attachEvent("message",a)};c.attachEvent=function(a,b){"undefined"!=typeof g.addEventListener? +g.addEventListener(a,b,!1):(j.attachEvent("on"+a,b),g.attachEvent("on"+a,b))};c.detachMessage=function(a){c.detachEvent("message",a)};c.detachEvent=function(a,b){"undefined"!=typeof g.addEventListener?g.removeEventListener(a,b,!1):(j.detachEvent("on"+a,b),g.detachEvent("on"+a,b))};var t={},C=!1,x=function(){for(var a in t)t[a](),delete t[a]},i=function(){C||(C=!0,x())};c.attachEvent("beforeunload",i);c.attachEvent("unload",i);c.unload_add=function(a){var b=c.random_string(8);return t[b]=a,C&&c.delay(x), +b};c.unload_del=function(a){a in t&&delete t[a]};c.createIframe=function(a,b){var f=j.createElement("iframe"),d,h,m=function(){clearTimeout(d);try{f.onload=null}catch(a){}f.onerror=null},g=function(){f&&(m(),setTimeout(function(){f&&f.parentNode.removeChild(f);f=null},0),c.unload_del(h))};return f.src=a,f.style.display="none",f.style.position="absolute",f.onerror=function(){f&&(g(),b("onerror"))},f.onload=function(){clearTimeout(d);d=setTimeout(function(){f&&(g(),b("onload timeout"))},2E3)},j.body.appendChild(f), +d=setTimeout(function(){f&&(g(),b("timeout"))},15E3),h=c.unload_add(g),{post:function(a,b){try{f&&f.contentWindow&&f.contentWindow.postMessage(a,b)}catch(c){}},cleanup:g,loaded:m}};c.createHtmlfile=function(a,b){var f=new ActiveXObject("htmlfile"),d,h,m,e=function(){clearTimeout(d)},j=function(){f&&(e(),c.unload_del(h),m.parentNode.removeChild(m),m=f=null,CollectGarbage())};f.open();f.write('<html><script>document.domain="'+document.domain+'";<\/script></html>');f.close();f.parentWindow._jp=g._jp; +var i=f.createElement("div");return f.body.appendChild(i),m=f.createElement("iframe"),i.appendChild(m),m.src=a,d=setTimeout(function(){f&&(j(),b("timeout"))},15E3),h=c.unload_add(j),{post:function(a,b){try{m&&m.contentWindow&&m.contentWindow.postMessage(a,b)}catch(c){}},cleanup:j,loaded:e}};i=function(){};i.prototype=new k(["chunk","finish"]);i.prototype._start=function(a,b,f,d){var h=this;try{h.xhr=new XMLHttpRequest}catch(m){}if(!h.xhr)try{h.xhr=new g.ActiveXObject("Microsoft.XMLHTTP")}catch(e){}if(g.ActiveXObject|| +g.XDomainRequest)b+=(-1===b.indexOf("?")?"?":"&")+"t="+ +new Date;h.unload_ref=c.unload_add(function(){h._cleanup(!0)});try{h.xhr.open(a,b,!0)}catch(j){h.emit("finish",0,"");h._cleanup();return}if(!d||!d.no_credentials)h.xhr.withCredentials="true";if(d&&d.headers)for(var i in d.headers)h.xhr.setRequestHeader(i,d.headers[i]);h.xhr.onreadystatechange=function(){if(h.xhr){var a=h.xhr;switch(a.readyState){case 3:try{var b=a.status,c=a.responseText}catch(d){}c&&0<c.length&&h.emit("chunk",b,c);break;case 4:h.emit("finish", +a.status,a.responseText),h._cleanup(!1)}}};h.xhr.send(f)};i.prototype._cleanup=function(a){if(this.xhr){c.unload_del(this.unload_ref);this.xhr.onreadystatechange=function(){};if(a)try{this.xhr.abort()}catch(b){}this.unload_ref=this.xhr=null}};i.prototype.close=function(){this.nuke();this._cleanup(!0)};(c.XHRCorsObject=function(){var a=this,b=arguments;c.delay(function(){a._start.apply(a,b)})}).prototype=new i;(c.XHRLocalObject=function(a,b,f){var d=this;c.delay(function(){d._start(a,b,f,{no_credentials:!0})})}).prototype= +new i;i=c.XDRObject=function(a,b,f){var d=this;c.delay(function(){d._start(a,b,f)})};i.prototype=new k(["chunk","finish"]);i.prototype._start=function(a,b,f){var d=this,h=new XDomainRequest,b=b+((-1===b.indexOf("?")?"?":"&")+"t="+ +new Date),g=h.ontimeout=h.onerror=function(){d.emit("finish",0,"");d._cleanup(!1)};h.onprogress=function(){d.emit("chunk",200,h.responseText)};h.onload=function(){d.emit("finish",200,h.responseText);d._cleanup(!1)};d.xdr=h;d.unload_ref=c.unload_add(function(){d._cleanup(!0)}); +try{d.xdr.open(a,b),d.xdr.send(f)}catch(e){g()}};i.prototype._cleanup=function(a){if(this.xdr){c.unload_del(this.unload_ref);this.xdr.ontimeout=this.xdr.onerror=this.xdr.onprogress=this.xdr.onload=null;if(a)try{this.xdr.abort()}catch(b){}this.unload_ref=this.xdr=null}};i.prototype.close=function(){this.nuke();this._cleanup(!0)};c.isXHRCorsCapable=function(){return g.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?1:g.XDomainRequest&&j.domain?2:s.enabled()?3:4};var e=function(a,b,f){var d=this, +h;d._options={devel:!1,debug:!1,protocols_whitelist:[],info:void 0,rtt:void 0};f&&c.objectExtend(d._options,f);d._base_url=c.amendUrl(a);d._server=d._options.server||c.random_number_string(1E3);d._options.protocols_whitelist&&d._options.protocols_whitelist.length?h=d._options.protocols_whitelist:("string"==typeof b&&0<b.length?h=[b]:c.isArray(b)?h=b:h=null,h&&d._debug('Deprecated API: Use "protocols_whitelist" option instead of supplying protocol list as a second parameter to SockJS constructor.')); +d._protocols=[];d.protocol=null;d.readyState=e.CONNECTING;d._ir=N(d._base_url);d._ir.onfinish=function(a,b){d._ir=null;a?(d._options.info&&(a=c.objectExtend(a,d._options.info)),d._options.rtt&&(b=d._options.rtt),d._applyInfo(a,b,h),d._didClose()):d._didClose(1002,"Can't connect to server",!0)}};e.prototype=new p;e.version="0.3.2";e.CONNECTING=0;e.OPEN=1;e.CLOSING=2;e.CLOSED=3;e.prototype._debug=function(){this._options.debug&&c.log.apply(c,arguments)};e.prototype._dispatchOpen=function(){this.readyState=== +e.CONNECTING?(this._transport_tref&&(clearTimeout(this._transport_tref),this._transport_tref=null),this.readyState=e.OPEN,this.dispatchEvent(new n("open"))):this._didClose(1006,"Server lost session")};e.prototype._dispatchMessage=function(a){this.readyState===e.OPEN&&this.dispatchEvent(new n("message",{data:a}))};e.prototype._dispatchHeartbeat=function(){this.readyState===e.OPEN&&this.dispatchEvent(new n("heartbeat",{}))};e.prototype._didClose=function(a,b,f){var d=this;if(d.readyState!==e.CONNECTING&& +d.readyState!==e.OPEN&&d.readyState!==e.CLOSING)throw Error("INVALID_STATE_ERR");d._ir&&(d._ir.nuke(),d._ir=null);d._transport&&(d._transport.doCleanup(),d._transport=null);var h=new n("close",{code:a,reason:b,wasClean:c.userSetCode(a)});if(!c.userSetCode(a)&&d.readyState===e.CONNECTING&&!f){if(d._try_next_protocol(h))return;h=new n("close",{code:2E3,reason:"All transports failed",wasClean:!1,last_event:h})}d.readyState=e.CLOSED;c.delay(function(){d.dispatchEvent(h)})};e.prototype._didMessage=function(a){switch(a.slice(0, +1)){case "o":this._dispatchOpen();break;case "a":for(var a=JSON.parse(a.slice(1)||"[]"),b=0;b<a.length;b++)this._dispatchMessage(a[b]);break;case "m":a=JSON.parse(a.slice(1)||"null");this._dispatchMessage(a);break;case "c":a=JSON.parse(a.slice(1)||"[]");this._didClose(a[0],a[1]);break;case "h":this._dispatchHeartbeat()}};e.prototype._try_next_protocol=function(a){var b=this;b.protocol&&(b._debug("Closed transport:",b.protocol,""+a),b.protocol=null);for(b._transport_tref&&(clearTimeout(b._transport_tref), +b._transport_tref=null);;){a=b.protocol=b._protocols.shift();if(!a)return!1;if(e[a]&&!0===e[a].need_body&&(!j.body||"undefined"!=typeof j.readyState&&"complete"!==j.readyState))return b._protocols.unshift(a),b.protocol="waiting-for-load",c.attachEvent("load",function(){b._try_next_protocol()}),!0;if(e[a]&&e[a].enabled(b._options)){b._transport_tref=c.delay((b._options.rto||0)*(e[a].roundTrips||1)||5E3,function(){b.readyState===e.CONNECTING&&b._didClose(2007,"Transport timeouted")});var f=c.random_string(8), +f=b._base_url+"/"+b._server+"/"+f;return b._debug("Opening transport:",a," url:"+f," RTO:"+b._options.rto),b._transport=new e[a](b,f,b._base_url),!0}b._debug("Skipping transport:",a)}};e.prototype.close=function(a,b){if(a&&!c.userSetCode(a))throw Error("INVALID_ACCESS_ERR");return this.readyState!==e.CONNECTING&&this.readyState!==e.OPEN?!1:(this.readyState=e.CLOSING,this._didClose(a||1E3,b||"Normal closure"),!0)};e.prototype.send=function(a){if(this.readyState===e.CONNECTING)throw Error("INVALID_STATE_ERR"); +return this.readyState===e.OPEN&&this._transport.doSend(c.quote(""+a)),!0};e.prototype._applyInfo=function(a,b,f){this._options.info=a;this._options.rtt=b;this._options.rto=c.countRTO(b);this._options.info.null_origin=!j.domain;b=c.probeProtocols();this._protocols=c.detectProtocols(b,f,a)};i=e.websocket=function(a,b){var f=this,d=b+"/websocket";"https"===d.slice(0,5)?d="wss"+d.slice(5):d="ws"+d.slice(4);f.ri=a;f.url=d;f.ws=new (g.WebSocket||g.MozWebSocket)(f.url);f.ws.onmessage=function(a){f.ri._didMessage(a.data)}; +f.unload_ref=c.unload_add(function(){f.ws.close()});f.ws.onclose=function(){f.ri._didMessage(c.closeFrame(1006,"WebSocket connection broken"))}};i.prototype.doSend=function(a){this.ws.send("["+a+"]")};i.prototype.doCleanup=function(){var a=this.ws;a&&(a.onmessage=a.onclose=null,a.close(),c.unload_del(this.unload_ref),this.unload_ref=this.ri=this.ws=null)};i.enabled=function(){return!!g.WebSocket||!!g.MozWebSocket};i.roundTrips=2;var l=function(){};l.prototype.send_constructor=function(a){this.send_buffer= +[];this.sender=a};l.prototype.doSend=function(a){this.send_buffer.push(a);this.send_stop||this.send_schedule()};l.prototype.send_schedule_wait=function(){var a=this,b;a.send_stop=function(){a.send_stop=null;clearTimeout(b)};b=c.delay(25,function(){a.send_stop=null;a.send_schedule()})};l.prototype.send_schedule=function(){var a=this;if(0<a.send_buffer.length){var b="["+a.send_buffer.join(",")+"]";a.send_stop=a.sender(a.trans_url,b,function(){a.send_stop=null;a.send_schedule_wait()});a.send_buffer= +[]}};l.prototype.send_destructor=function(){this._send_stop&&this._send_stop();this._send_stop=null};var O=function(a,b,f){if(!("_send_form"in this)){var d=this._send_form=j.createElement("form"),h=this._send_area=j.createElement("textarea");h.name="d";d.style.display="none";d.style.position="absolute";d.method="POST";d.enctype="application/x-www-form-urlencoded";d.acceptCharset="UTF-8";d.appendChild(h);j.body.appendChild(d)}var d=this._send_form,h=this._send_area,g="a"+c.random_string(8);d.target= +g;d.action=a+"/jsonp_send?i="+g;var e;try{e=j.createElement('<iframe name="'+g+'">')}catch(i){e=j.createElement("iframe"),e.name=g}e.id=g;d.appendChild(e);e.style.display="none";try{h.value=b}catch(k){c.log("Your browser is seriously broken. Go home! "+k.message)}d.submit();var l=function(){e.onerror&&(e.onreadystatechange=e.onerror=e.onload=null,c.delay(500,function(){e.parentNode.removeChild(e);e=null}),h.value="",f())};return e.onerror=e.onload=l,e.onreadystatechange=function(){"complete"==e.readyState&& +l()},l},P=function(a){return function(b,c,d){return(new a("POST",b+"/xhr_send",c)).onfinish=function(a){d(a)},function(a){d(0,a)}}},i=e["jsonp-polling"]=function(a,b){c.polluteGlobalNamespace();this.ri=a;this.trans_url=b;this.send_constructor(O);this._schedule_recv()};i.prototype=new l;i.prototype._schedule_recv=function(){var a=this,b=a.trans_url+"/jsonp",f="a"+c.random_string(6),b=b+"?c="+escape("_jp."+f),d=function(b){delete g._jp[f];a._recv_stop=null;b&&(a._is_closing||a.ri._didMessage(b));a._is_closing|| +a._schedule_recv()},e,m=j.createElement("script"),i,k=function(a){i&&(i.parentNode.removeChild(i),i=null);m&&(clearTimeout(e),m.parentNode.removeChild(m),m.onreadystatechange=m.onerror=m.onload=m.onclick=null,m=null,d(a),d=null)},l=!1,p=null;m.id="a"+c.random_string(8);m.src=b;m.type="text/javascript";m.charset="UTF-8";m.onerror=function(){p||(p=setTimeout(function(){l||k(c.closeFrame(1006,"JSONP script loaded abnormally (onerror)"))},1E3))};m.onload=function(){k(c.closeFrame(1006,"JSONP script loaded abnormally (onload)"))}; +m.onreadystatechange=function(){if(/loaded|closed/.test(m.readyState)){if(m&&m.htmlFor&&m.onclick){l=!0;try{m.onclick()}catch(a){}}m&&k(c.closeFrame(1006,"JSONP script loaded abnormally (onreadystatechange)"))}};if("undefined"==typeof m.async&&j.attachEvent)if(/opera/i.test(navigator.userAgent))i=j.createElement("script"),i.text="try{var a = document.getElementById('"+m.id+"'); if(a)a.onerror();}catch(x){};",m.async=i.async=!1;else{try{m.htmlFor=m.id,m.event="onclick"}catch(n){}m.async=!0}"undefined"!= +typeof m.async&&(m.async=!0);e=setTimeout(function(){k(c.closeFrame(1006,"JSONP script loaded abnormally (timeout)"))},35E3);b=j.getElementsByTagName("head")[0];b=(b.insertBefore(m,b.firstChild),i&&b.insertBefore(i,b.firstChild),k);g._jp[f]=b;a._recv_stop=function(){g._jp[f]&&g._jp[f](c.closeFrame(1E3,"JSONP user aborted read"))}};i.enabled=function(){return!0};i.need_body=!0;i.prototype.doCleanup=function(){this._is_closing=!0;this._recv_stop&&this._recv_stop();this.ri=this._recv_stop=null;this.send_destructor()}; +i=function(){};i.prototype=new l;i.prototype.run=function(a,b,c,d,e){this.ri=a;this.trans_url=b;this.send_constructor(P(e));this.poll=new E(a,d,b+c,e)};i.prototype.doCleanup=function(){this.poll&&(this.poll.abort(),this.poll=null)};var w=e["xhr-streaming"]=function(a,b){this.run(a,b,"/xhr_streaming",y,c.XHRCorsObject)};w.prototype=new i;w.enabled=function(){return g.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest&&!/opera/i.test(navigator.userAgent)};w.roundTrips=2;w.need_body=!0;l=e["xdr-streaming"]= +function(a,b){this.run(a,b,"/xhr_streaming",y,c.XDRObject)};l.prototype=new i;l.enabled=function(){return!!g.XDomainRequest};l.roundTrips=2;var F=e["xhr-polling"]=function(a,b){this.run(a,b,"/xhr",y,c.XHRCorsObject)};F.prototype=new i;F.enabled=w.enabled;F.roundTrips=2;w=e["xdr-polling"]=function(a,b){this.run(a,b,"/xhr",y,c.XDRObject)};w.prototype=new i;w.enabled=l.enabled;w.roundTrips=2;var s=function(){};s.prototype.i_constructor=function(a,b,f){var d=this;d.ri=a;d.origin=c.getOrigin(f);d.base_url= +f;d.trans_url=b;a=f+"/iframe.html";d.ri._options.devel&&(a+="?t="+ +new Date);d.window_id=c.random_string(8);a+="#"+d.window_id;d.iframeObj=c.createIframe(a,function(a){d.ri._didClose(1006,"Unable to load an iframe ("+a+")")});d.onmessage_cb=c.bind(d.onmessage,d);c.attachMessage(d.onmessage_cb)};s.prototype.doCleanup=function(){if(this.iframeObj){c.detachMessage(this.onmessage_cb);try{this.iframeObj.iframe.contentWindow&&this.postMessage("c")}catch(a){}this.iframeObj.cleanup();this.onmessage_cb=this.iframeObj= +this.iframeObj=null}};s.prototype.onmessage=function(a){if(a.origin===this.origin){var b=a.data.slice(0,8),c=a.data.slice(8,9),a=a.data.slice(9);if(b===this.window_id)switch(c){case "s":this.iframeObj.loaded();this.postMessage("s",JSON.stringify([e.version,this.protocol,this.trans_url,this.base_url]));break;case "t":this.ri._didMessage(a)}}};s.prototype.postMessage=function(a,b){this.iframeObj.post(this.window_id+a+(b||""),this.origin)};s.prototype.doSend=function(a){this.postMessage("m",a)};s.enabled= +function(){var a=navigator&&navigator.userAgent&&-1!==navigator.userAgent.indexOf("Konqueror");return("function"==typeof g.postMessage||"object"==typeof g.postMessage)&&!a};var G,H=function(a,b){parent!==g?parent.postMessage(G+a+(b||""),"*"):c.log("Can't postMessage, no parent window.",a,b)},u=function(){};u.prototype._didClose=function(a,b){H("t",c.closeFrame(a,b))};u.prototype._didMessage=function(a){H("t",a)};u.prototype._doSend=function(a){this._transport.doSend(a)};u.prototype._doCleanup=function(){this._transport.doCleanup()}; +c.parent_origin=void 0;e.bootstrap_iframe=function(){var a;G=j.location.hash.slice(1);c.attachMessage(function(b){if(b.source===parent&&("undefined"==typeof c.parent_origin&&(c.parent_origin=b.origin),b.origin===c.parent_origin)){var f=b.data.slice(0,8),d=b.data.slice(8,9),b=b.data.slice(9);if(f===G)switch(d){case "s":var h=JSON.parse(b),f=h[0],d=h[1],b=h[2],h=h[3];f!==e.version&&c.log('Incompatibile SockJS! Main site uses: "'+f+'", the iframe: "'+e.version+'".');if(!c.flatUrl(b)||!c.flatUrl(h)){c.log("Only basic urls are supported in SockJS"); +break}if(!c.isSameOriginUrl(b)||!c.isSameOriginUrl(h)){c.log("Can't connect to different domain from within an iframe. ("+JSON.stringify([g.location.href,b,h])+")");break}a=new u;a._transport=new u[d](a,b,h);break;case "m":a._doSend(b);break;case "c":a&&a._doCleanup(),a=null}}});H("s")};var z=function(a,b){var f=this;c.delay(function(){f.doXhr(a,b)})};z.prototype=new k(["finish"]);z.prototype.doXhr=function(a,b){var f=this,d=(new Date).getTime(),e=new b("GET",a+"/info"),g=c.delay(8E3,function(){e.ontimeout()}); +e.onfinish=function(a,b){clearTimeout(g);g=null;if(200===a){var c=(new Date).getTime()-d,e=JSON.parse(b);"object"!=typeof e&&(e={});f.emit("finish",e,c)}else f.emit("finish")};e.ontimeout=function(){e.close();f.emit("finish")}};var K=function(a){var b=this,f=function(){var c=new s;c.protocol="w-iframe-info-receiver";var f=function(a){"string"==typeof a&&"m"===a.substr(0,1)?(a=JSON.parse(a.substr(1)),b.emit("finish",a[0],a[1])):b.emit("finish");c.doCleanup();c=null};c.i_constructor({_options:{},_didClose:f, +_didMessage:f},a,a)};j.body?f():c.attachEvent("load",f)};K.prototype=new k(["finish"]);var L=function(){var a=this;c.delay(function(){a.emit("finish",{},2E3)})};L.prototype=new k(["finish"]);var N=function(a){if(c.isSameOriginUrl(a))return new z(a,c.XHRLocalObject);switch(c.isXHRCorsCapable()){case 1:return new z(a,c.XHRLocalObject);case 2:return new z(a,c.XDRObject);case 3:return new K(a);default:return new L}};(u["w-iframe-info-receiver"]=function(a,b,f){(new z(f,c.XHRLocalObject)).onfinish=function(b, +c){a._didMessage("m"+JSON.stringify([b,c]));a._didClose()}}).prototype.doCleanup=function(){};k=e["iframe-eventsource"]=function(){this.protocol="w-iframe-eventsource";this.i_constructor.apply(this,arguments)};k.prototype=new s;k.enabled=function(){return"EventSource"in g&&s.enabled()};k.need_body=!0;k.roundTrips=3;(u["w-iframe-eventsource"]=function(a,b){this.run(a,b,"/eventsource",I,c.XHRLocalObject)}).prototype=new i;k=e["iframe-xhr-polling"]=function(){this.protocol="w-iframe-xhr-polling";this.i_constructor.apply(this, +arguments)};k.prototype=new s;k.enabled=function(){return g.XMLHttpRequest&&s.enabled()};k.need_body=!0;k.roundTrips=3;(u["w-iframe-xhr-polling"]=function(a,b){this.run(a,b,"/xhr",y,c.XHRLocalObject)}).prototype=new i;k=e["iframe-htmlfile"]=function(){this.protocol="w-iframe-htmlfile";this.i_constructor.apply(this,arguments)};k.prototype=new s;k.enabled=function(){return s.enabled()};k.need_body=!0;k.roundTrips=3;(u["w-iframe-htmlfile"]=function(a,b){this.run(a,b,"/htmlfile",J,c.XHRLocalObject)}).prototype= +new i;var E=function(a,b,c,d){this.ri=a;this.Receiver=b;this.recv_url=c;this.AjaxObject=d;this._scheduleRecv()};E.prototype._scheduleRecv=function(){var a=this,b=a.poll=new a.Receiver(a.recv_url,a.AjaxObject);b.onmessage=function(b){a.ri._didMessage(b.data)};b.onclose=function(c){a.poll=b=b.onmessage=b.onclose=null;a.poll_is_closing||("permanent"===c.reason?a.ri._didClose(1006,"Polling error ("+c.reason+")"):a._scheduleRecv())}};E.prototype.abort=function(){this.poll_is_closing=!0;this.poll&&this.poll.abort()}; +var I=function(a){var b=this,f=new EventSource(a);f.onmessage=function(a){b.dispatchEvent(new n("message",{data:unescape(a.data)}))};b.es_close=f.onerror=function(a,e){var g=e?"user":2!==f.readyState?"network":"permanent";b.es_close=f.onmessage=f.onerror=null;f.close();f=null;c.delay(200,function(){b.dispatchEvent(new n("close",{reason:g}))})}};I.prototype=new p;I.prototype.abort=function(){this.es_close&&this.es_close({},!0)};var A,J=function(a){var b=this;c.polluteGlobalNamespace();b.id="a"+c.random_string(6, +26);a+=(-1===a.indexOf("?")?"?":"&")+"c="+escape("_jp."+b.id);if(void 0===A)if("ActiveXObject"in g)try{A=!!new ActiveXObject("htmlfile")}catch(f){}else A=!1;var d=A?c.createHtmlfile:c.createIframe,e;g._jp[b.id]={start:function(){e.loaded()},message:function(a){b.dispatchEvent(new n("message",{data:a}))},stop:function(){b.iframe_close({},"network")}};b.iframe_close=function(a,c){e.cleanup();b.iframe_close=e=null;delete g._jp[b.id];b.dispatchEvent(new n("close",{reason:c}))};e=d(a,function(){b.iframe_close({}, +"permanent")})};J.prototype=new p;J.prototype.abort=function(){this.iframe_close&&this.iframe_close({},"user")};var y=function(a,b){var c=this,d=0;c.xo=new b("POST",a,null);c.xo.onchunk=function(a,b){if(200===a)for(;;){var e=b.slice(d),g=e.indexOf("\n");if(-1===g)break;d+=g+1;e=e.slice(0,g);c.dispatchEvent(new n("message",{data:e}))}};c.xo.onfinish=function(a,b){c.xo.onchunk(a,b);c.xo=null;c.dispatchEvent(new n("close",{reason:200===a?"network":"permanent"}))}};return y.prototype=new p,y.prototype.abort= +function(){this.xo&&(this.xo.close(),this.dispatchEvent(new n("close",{reason:"user"})),this.xo=null)},e.getUtils=function(){return c},e.getIframeTransport=function(){return s},e}();"_sockjs_onload"in window&&setTimeout(_sockjs_onload,1);"function"==typeof define&&define.amd&&define("sockjs",[],function(){return SockJS});function WebTCP(j,g){this.sockets={};this.httpClients={};this.sock=new SockJS("http://"+j+":"+g+"/bridge");this.ready=!1;this.outputBuffer=[];var c=this;this.sock.onopen=function(){c.ready=!0;c.processBuffer()};this.processBuffer=function(){if(0<this.outputBuffer.length&&this.ready)for(var c in this.outputBuffer)this.sock.send(this.outputBuffer[c])};this.sock.onmessage=function(g){g.data=JSON.parse(g.data);g.data.sID?(sID=g.data.sID,c.sockets[sID].onEvent(g.data.eventName,g.data.data)):g.data.cID&& +(cID=g.data.cID,c.httpClients[cID].onEvent(g.data.eventName,g.data.data))};this.sock.onclose=function(){console.log("close")};this.createSocket=function(c,g,j){return new Socket(this,c,g,j)};this.createHTTPClient=function(){return new Http(this)}};function WebTCPIO(){this.onEvent=function(j,g){this["on"+j](g);if(this["on"+j+"Custom"])this["on"+j+"Custom"](g)};this.on=function(j,g){this["on"+j+"Custom"]=g};this.rpc=function(j,g){var c=this.createPacket();c.command=j;c.args=g;this.send(JSON.stringify(c));return c.id};this.write=function(j){var g=this.createPacket();g.data=j;this.send(JSON.stringify(g));return g.id};this.send=function(j){if(this.webtcp.ready)this.webtcp.sock.send(j);else{if(this.webtcp.outputBuffer>this.webtcp.BUFF_SIZE)throw"Output buffer is already full, but sockJS connection is not ready yet"; +this.webtcp.outputBuffer.push(j)}};this.onerror=function(j){throw j;}};
\ No newline at end of file diff --git a/src/main/java/com/seaofnodes/simple/IterPeeps.java b/src/main/java/com/seaofnodes/simple/IterPeeps.java index c4b96c5c..a3b66e09 100644 --- a/src/main/java/com/seaofnodes/simple/IterPeeps.java +++ b/src/main/java/com/seaofnodes/simple/IterPeeps.java @@ -1,6 +1,8 @@ package com.seaofnodes.simple; import com.seaofnodes.simple.codegen.CodeGen; +import com.seaofnodes.simple.type.Type; +import com.seaofnodes.simple.type.TypeInteger; import com.seaofnodes.simple.util.Ary; import com.seaofnodes.simple.node.*; import java.util.Arrays; @@ -45,7 +47,7 @@ import java.util.Random; */ public class IterPeeps { - private final WorkList<Node> _work; + public final WorkList<Node> _work; private final WorkList<CallEndNode> _workInline; @@ -74,7 +76,7 @@ public class IterPeeps { // Only try growing inlines once the shrinking peepholes reach a fixed point. private void iteratePeeps( CodeGen code ) { - assert progressOnList(code); + assert progressOnList(code, _work, true); int cnt=0; Node n; @@ -109,7 +111,7 @@ public class IterPeeps { } // If there are distant neighbors, move to worklist n.moveDepsToWorklist(); - assert progressOnList(code); // Very expensive assert + assert progressOnList(code, _work, true); // Very expensive assert } if( n.isUnused() && !(n instanceof StopNode) ) n.kill(); // Just plain dead @@ -130,18 +132,24 @@ public class IterPeeps { // neighbors and these should fail, but will then try to add dependencies // {@link #Node.addDep} which is a side effect in an assert. The {@link // #midAssert} is used to stop this side effect. - private boolean progressOnList(CodeGen code) { + // Pessimistic solver assert + public static boolean progressOnList(CodeGen code, WorkList<Node> list, boolean dir ) { code._midAssert = true; Node changed = code._stop.walk( n -> { - Node m = n; - if( n.compute().isa(n._type) && (!n.iskeep() || n._nid<=6) ) { // Types must be forwards, even if on worklist - if( _work.on(n) ) return null; - m = n.peepholeOpt(); - if( m==null ) return null; - } - System.err.println("BREAK HERE FOR BUG"); - return m; - }); + Node m = n; + Type nval = n.compute(); + if( (!n.iskeep() || n._nid<=8) && // Types must be forwards, even if on worklist + ( dir + ? nval.isa(n._type) // Pesi: new value lifts over old + : n._type.isa(nval) // Opto: new value falls over old + ) ) { + if( list.on(n) ) return null; + m = n.peepholeOpt(); + if( m==null ) return null; + } + System.err.println("BREAK HERE FOR BUG"); + return m; + }); code._midAssert = false; return changed==null; } @@ -197,7 +205,7 @@ public class IterPeeps { /** * True if Node is on the WorkList */ - boolean on( E x ) { return _on.get(x._nid); } + public boolean on( E x ) { return _on.get(x._nid); } boolean isEmpty() { return _len==0; } /** diff --git a/src/main/java/com/seaofnodes/simple/Parser.java b/src/main/java/com/seaofnodes/simple/Parser.java index 6084eaa5..9cf565ac 100644 --- a/src/main/java/com/seaofnodes/simple/Parser.java +++ b/src/main/java/com/seaofnodes/simple/Parser.java @@ -133,7 +133,7 @@ public class Parser { public void parse() { // Graph callbacks during scope setup need a source position. - _lexer = new Lexer(com.seaofnodes.simple.sys.SYS); + _lexer = new Lexer(sys.SYS); _scope.define(ScopeNode.CTRL, Type.CONTROL , false, null, _lexer); _scope.define(ScopeNode.MEM0, TypeMem.BOT , false, null, _lexer); @@ -160,18 +160,26 @@ public class Parser { // default main). FunNode main = _code.link(_code._main); StopNode stop = _code._stop; + // Gather an explicit main + FunNode xmain = null; + for( Node n : stop._inputs ) + if( n instanceof ReturnNode ret && "main".equals(ret.fun()._name) ) + if( xmain != null ) throw Utils.TODO(); + else xmain = ret.fun(); + if( main.ret().expr()._type==Type.TOP && main.uctrl()==null ) { // Kill an empty default main; so it does not attempt to put a // "main" in any final ELF file main.setDef(1,XCTRL); // Delete default start input stop.delDef(stop._inputs.find(main.ret())); + if( xmain != null ) + _code.setMain(xmain); + } else { // We have a non-empty default main. - // Check for an explicit main - for( Node n : stop._inputs ) - if( n instanceof FunNode fun && fun._name.equals("main") ) - // Found an explicit "main" AND we have a default "main" - throw error("Cannot define both an explicit main and a default main"); + if( xmain != null ) + // Found an explicit "main" AND we have a default "main" + throw error("Cannot define both an explicit main and a default main"); main._name = "main"; } @@ -540,9 +548,8 @@ public class Parser { // Parse a conditional expression, merging results. private Node parseTrinary( Node pred, String fside ) { - pred.keep(); - // IfNode takes current control and predicate + pred.keep(); Node ifNode = new IfNode(ctrl(), pred).peephole(); // Setup projection nodes Node ifT = new CProjNode(ifNode. keep(), 0, "True" ).peephole().keep(); @@ -708,7 +715,7 @@ public class Parser { // Type is sane if( et!=Type.BOTTOM && (!et.shallowISA(t) || !et.accessISA(t)) ) - expr = peep(new CastNode(t,null,expr)); + expr = peep(new CastNode(t.isConstant() ? t : t.widen(),null,expr)); return expr; } @@ -822,7 +829,7 @@ public class Parser { // Lift type to the declaration. This will report as an error later if // we cannot lift the type. if( !lift._type.isa(t) ) - lift = peep(new CastNode(t,null,lift)); + lift = peep(new CastNode(t.widen(),null,lift)); // Define a new name if( !_scope.define(name,t,xfinal || fld_final,lift, loc) ) throw error("Redefining name '" + name + "'", loc); @@ -1050,49 +1057,100 @@ public class Parser { } private Node parseBitwise() { - Node lhs = parseComparison(); + Node lhs = parseEquality(); while( true ) { if( false ) ; else if( matchOp('&') ) lhs = new AndNode(loc(),lhs,null); else if( matchOp('|') ) lhs = new OrNode(loc(),lhs,null); else if( match ("^") ) lhs = new XorNode(loc(),lhs,null); else break; - lhs.setDef(2,parseComparison()); + lhs.setDef(2,parseEquality()); lhs = peep(lhs); } return lhs; } + + + /** + * Parse an eq/ne expression + */ + private Node parseEquality() { + Node lhs = parseComparison(); + while( true ) { + boolean eq = false; + if( match("==") ) eq = true; + else if( !match("!=") ) break; + lhs.keep(); + Node rhs = parseComparison(); + lhs = peep(new BoolNode.EQ(lhs.unkeep(),rhs).widen()); + if( !eq ) lhs = peep(new NotNode(lhs)); + } + return lhs; + } + /** * Parse an expression of the form: * * <pre> - * expr : additiveExpr op additiveExpr + * expr : shiftExpr < shiftExpr <= shiftExpr... + * expr : shiftExpr > shiftExpr >= shiftExpr... * </pre> * @return an comparator expression {@link Node}, never {@code null} */ private Node parseComparison() { - var lhs = parseShift(); + Node lhs = parseShift(); + int dir = 0; + while( true ) { - int idx=0; boolean negate=false; - // Test for any local nodes made, and "keep" lhs during peepholes + int dir0; if( false ) ; - else if( match("==") ) { idx=2; lhs = new BoolNode.EQ(lhs, null); } - else if( match("!=") ) { idx=2; lhs = new BoolNode.EQ(lhs, null); negate=true; } - else if( match("<=") ) { idx=2; lhs = new BoolNode.LE(lhs, null); } - else if( match("<" ) ) { idx=2; lhs = new BoolNode.LT(lhs, null); } - else if( match(">=") ) { idx=1; lhs = new BoolNode.LE(null, lhs); } - else if( match(">" ) ) { idx=1; lhs = new BoolNode.LT(null, lhs); } + else if( match("<=" ) ) dir0 = -1; + else if( match(">=" ) ) dir0 = -2; + else if( match("<" ) ) dir0 = 1; + else if( match(">" ) ) dir0 = 2; else break; - // Peepholes can fire, but lhs is already "hooked", kept alive - lhs.setDef(idx,parseShift()); - lhs = peep(lhs.widen()); - if( negate ) // Extra negate for != - lhs = peep(new NotNode(lhs)); + lhs.keep(); + // Check and record direction + if( dir==0 ) { + dir = Math.abs(dir0); + Node rhs = parseShift(); + lhs = makeCompBool(dir0,lhs.unkeep(),rhs); // Convert to a bool + } else if( dir == Math.abs(dir0) ) { + // e0 < lhs < ??? + Node ifNode = new IfNode(ctrl(), lhs).peephole(); + Node ifT = new CProjNode(ifNode. keep(), 0, "True" ).peephole(); + Node ifF = new CProjNode(ifNode.unkeep(), 1, "False").peephole(); + // False side does nothing + ScopeNode fScope = _scope.dup(); + fScope.ctrl(ifF); + // True side executes next part of range + ctrl(ifT); + _scope.addGuards(ifT,lhs,false); + Node rhs = parseShift(); + _scope.removeGuards(ifT); // TODO: I think should remain true as long as possible + Node next = makeCompBool(dir0, lhs, rhs).keep(); + // Merge result + RegionNode r = ctrl(_scope.mergeScopes(fScope, loc())); + assert next._type.meet(lhs._type).isa( TypeInteger.BOOL ); + lhs = peep(new PhiNode("",TypeInteger.BOOL,r,next.unkeep(),lhs.unkeep())); + r.peephole(); + } else { + throw error("Mixing relational directions in a chained relational test"); + } } return lhs; } + private Node makeCompBool( int dir0, Node lhs, Node rhs ) { + // Convert to a bool + if( Math.abs(dir0)==2 ) // Swap direction + { Node tmp = lhs; lhs = rhs; rhs = tmp; } + lhs = peep(dir0 < 0 ? new BoolNode.LE(lhs,rhs) : new BoolNode.LT(lhs,rhs)); + return peep(lhs.widen()); + } + + /** * Parse an additive expression * @@ -1523,6 +1581,8 @@ public class Parser { Type tf = f._t; if( tf instanceof TypeMemPtr ftmp && ftmp.isFRef() ) tf = ftmp.makeFrom(((TypeMemPtr)(TYPES.get(ftmp._obj._name)))._obj); + if( base.isAry() && tf instanceof TypeConAry con ) + tf = con.elem(); expr.keep(); // Field offset; fixed for structs, computed for arrays @@ -1685,7 +1745,6 @@ public class Parser { // Into the call CallNode call = (CallNode)new CallNode(loc(), args.asAry()).peephole(); - // Post-call setup CallEndNode cend = (CallEndNode)new CallEndNode(call).peephole(); call.peephole(); // Rerun peeps after CallEnd, allows early inlining diff --git a/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java b/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java index 9bf1aa61..f3d3dee3 100644 --- a/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java +++ b/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java @@ -9,6 +9,7 @@ import com.seaofnodes.simple.print.*; import com.seaofnodes.simple.type.*; import com.seaofnodes.simple.util.Ary; import com.seaofnodes.simple.util.SB; +import com.seaofnodes.simple.util.Utils; import java.io.IOException; import java.util.*; @@ -33,7 +34,6 @@ public class CodeGen { Export, // Export } public Phase _phase; - // --------------------------- // Compilation source code public final String _src; @@ -117,7 +117,7 @@ public class CodeGen { // are structurally equal. public final HashMap<Node,Node> _gvn = new HashMap<>(); - // + // Source of unique function indices private int _fidx =0; public TypeFunPtr makeFun( TypeFunPtr fun ) { int fidx = _fidx++; @@ -125,23 +125,36 @@ public class CodeGen { return fun.makeFrom(fidx); } // Signature for MAIN - public final TypeFunPtr _main; - // Reverse from a constant function pointer to the IR function being called - public FunNode link( TypeFunPtr tfp ) { - assert tfp.isConstant(); - return _linker.get(tfp.makeFrom(Type.BOTTOM)); + public TypeFunPtr _main; + public void setMain(FunNode main) { + _main = main.sig(); + link(main); + } + // Reverse from a constant function pointer to the IR function being called. + // Error to call with a non-constant TFP + public FunNode link( TypeFunPtr tfp ) { return link(tfp.fidx()); } + // Read-only diagnostic lookup; preserve stale entries. + public FunNode _link(TypeFunPtr tfp) { return _link(tfp.fidx()); } + public FunNode _link(int fidx) { return _linker.atX(fidx); } + // Return the FunNode from a fidx, cleaning up dead entries. + public FunNode link( int fidx ) { + FunNode fun =_linker.atX(fidx); + if( fun!=null && fun.isDead() ) { + _linker.setX(fidx,null); fun = null; } + return fun; } // Insert linker mapping from constant function signature to the function // being called. public void link(FunNode fun) { - _linker.put(fun.sig().makeFrom(Type.BOTTOM),fun); + int fidx = fun.sig().fidx(); + _linker.setX(fidx,fun); } // "Linker" mapping from constant TypeFunPtrs to heads of function. These // TFPs all have exact single fidxs and their return is wiped to BOTTOM (so // the return is not part of the match). - private final HashMap<TypeFunPtr,FunNode> _linker = new HashMap<>(); + final Ary<FunNode> _linker = new Ary<>(FunNode.class); // Parser object public final Parser P; @@ -178,60 +191,15 @@ public class CodeGen { _phase = Phase.Opto; long t0 = System.currentTimeMillis(); - // Pessimistic peephole optimization on a worklist - _iter.iterate(this); - - // OPTIMISTIC PASS GOES HERE - - // Not really a true optimistic pass, but look for unlinked functions. - // This can be removed, which may trigger another round of pessimistic. - // This is the point where we flip from a virtual Call Graph (any call - // can call any function) to having a correct (but conservative) CG. - int progress = 0; - while( progress != _start.nOuts() ) { - progress = _start.nOuts(); - FunNode main = link(_main); - for( int i=0; i<_start.nOuts(); i++ ) { - Node use = _start.out(i); - if( use instanceof FunNode fun && - fun.nIns()==2 && fun.in(1)==_start && fun != main && !fun.hasPtr() && - (fun._name==null || fun._name.startsWith("sys.")) ) { - add(fun).setDef(1,Parser.XCTRL); - addAll(fun._outputs); - i--; - } - } - _iter.iterate(this); - } - - // Freeze field sizes; do struct layouts; convert field offsets into - // constants. - for( int i=0; i<_start.nOuts(); i++ ) { - Node use = _start.out(i); - if( use instanceof ConFldOffNode off ) { - TypeMemPtr tmp = (TypeMemPtr) Parser.TYPES.get(off._name); - off.subsume( off.asOffset(tmp._obj) ); - i--; - } - } - _iter.iterate(this); - - // To help with testing, sort StopNode returns by NID - Arrays.sort(_stop._inputs._es,0,_stop.nIns(),(x,y) -> x._nid - y._nid ); + Opto.opto(this); _tOpto = (int)(System.currentTimeMillis() - t0); - - // TODO: - // Optimistic - // TODO: - // loop unroll, peel, RCE, etc if( _obs != null ) _obs.phase("Opto"); return this; } public <N extends Node> N add( N n ) { return _iter.add(n); } public void addAll( Ary<Node> ary ) { _iter.addAll(ary); } - // --------------------------- // Last check for bad programs public int _tTypeCheck; diff --git a/src/main/java/com/seaofnodes/simple/codegen/Encoding.java b/src/main/java/com/seaofnodes/simple/codegen/Encoding.java index 5099c02a..b5a8e148 100644 --- a/src/main/java/com/seaofnodes/simple/codegen/Encoding.java +++ b/src/main/java/com/seaofnodes/simple/codegen/Encoding.java @@ -193,12 +193,16 @@ public class Encoding implements com.seaofnodes.isa.CodeSink { rpos.put(_code._start.loop(),rpo); BitSet visit = _code.visit(); rpo.add(_code._stop); + FunNode main = _code.link(_code._main); for( Node n : _code._start._outputs ) - if( n instanceof FunNode fun ) { + if( n instanceof FunNode fun && fun != main ) { int x = rpo._len; _rpo_cfg(fun, visit, rpos ); assert rpo.at(x) instanceof ReturnNode; } + // Do any main function last... so it lands at offset 0 in the RPO + if( main!=null ) + _rpo_cfg(main, visit, rpos ); rpo.add(_code._start); // Reverse in-place diff --git a/src/main/java/com/seaofnodes/simple/codegen/Opto.java b/src/main/java/com/seaofnodes/simple/codegen/Opto.java new file mode 100644 index 00000000..cd52aadd --- /dev/null +++ b/src/main/java/com/seaofnodes/simple/codegen/Opto.java @@ -0,0 +1,267 @@ +package com.seaofnodes.simple.codegen; + +import com.seaofnodes.simple.Parser; +import com.seaofnodes.simple.node.*; +import com.seaofnodes.simple.type.*; +import com.seaofnodes.simple.util.Ary; +import java.util.Arrays; + +// Optimistic Algorithm +abstract public class Opto { + + // Optimistic analysis - extended SCCP + + // Start all Types at TOP, and propagate changes until stable. Unlike a + // normal Sparse Conditional Constant Propagation, this version is + // interprocedural, computing effectively CFA0 in linear time using the + // normal SCCP algorithm. + + // This algo also builds a Call Graph; as Calls become reachable (CONTROL + // not TOP nor XCONTROL), they "link" against the reaching function + // pointers - adding edges from the Call to the Fun, and from the Return to + // the CallEnd. This allows the normal algorithm to use the normal edge + // propagation rules as function argument types stabilize. In the end, we + // get a fairly precise set of Call Graph edges between CallNodes and + // FunNodes. + public static void opto(CodeGen code) { + + // Pessimistic peephole optimization on a worklist - this completes + // whatever peepholes can run after parsing. + code._iter.iterate(code); + + // Reset Types before running the worklist algorithm + Ary<Type> oldTypes = new Ary<>(Type.class); // Used for asserts only + resetToTop(code,oldTypes); + + // The whole-world assumption: we use it if compiling `main`, and not otherwise. + // The assumption is no unknown callers into functions: + // - during or past an Opto phase (but not before, since parse through + // pessimistic must assume somebody calls an unknown function which + // calls everybody). + // - Have a `main` to start tracing the Call Graph from + // - - True for most test cases + // - - False for lacking a main; we assume the linker will call all public functions + + // True if we can make the "whole world" assumption, which means we are + // compiling the program entry: `main`. + boolean wholeWorld = code.link(code._main) != null; + + + // If wholeWorld, remove the Start inputs to functions - they are not + // called unless they get linked (hence go dead and can be removed). + // If not wholeWorld, keep only public methods (and not the std lib). + unlinkStart(wholeWorld,code); + + + // OPTIMISTIC INTERPROCEDURAL SCCP + sccp(code, oldTypes); + + // After SCCP add everything changed to the worklist and see if + // peepholes can make more progress. + moveChangesToWorklist(code, oldTypes); + + // Progress with improved types. E.g. since we have a full Call Graph + // here, we might do better inlining. + code._iter.iterate(code); + + // TODO: + // loop unroll, peel, RCE, etc + + // Freeze field sizes; do struct layouts; convert field offsets into + // constants. + fieldSizes(code); + // Propagate field size constants + code._iter.iterate(code); + + // Throw away the Call Graph + + // The remaining passes assume all calls are unlinked; i.e. we are + // throwing away the Call Graph here. Functions only reachable from + // internal calls need to be re-hooked to stop/start less they go dead. + removeCallGraph(code); + + // To help with testing, sort StopNode Returns by NID + Arrays.sort(code._stop._inputs._es,0,code._stop.nIns(),(x,y) -> x._nid - y._nid ); + } + + // Reset Types before running the worklist algorithm + private static void resetToTop(CodeGen code, Ary<Type> oldTypes ) { + code._start.walk( x -> { + oldTypes.setX(x._nid,x._type); // Record original types for asserts + x._type = Type.TOP; // Reset all Nodes to TOP + code._iter.add(x); // Visit everybody at least once; most Nodes produce better than TOP + // Unlink all existing (conservative) linkages. + if( x instanceof CallNode call ) + call.unlink_all(); + return null; + } ); + } + + + // If wholeWorld, remove the Start inputs to functions - they are not + // called unless they get linked (hence go dead and can be removed). If + // not wholeWorld, keep only public methods (and not the std lib). + private static void unlinkStart(boolean wholeWorld, CodeGen code) { + for( FunNode fun : code._linker ) { + if( fun != null && !fun.isDead() && !funIsPublic(code,wholeWorld,fun) ) { + assert fun.in(1)==code._start; // Start always in slot 1 + fun.removeDeadPath(1); + // By same logic, remove stop->return linkage, without + // remove the (now dead) ReturnNode; it awaits in limbo + // for the opto phase to link to some valid call + code._stop._inputs.del(code._stop._inputs.find(fun.ret())); + fun.ret().delUse(code._stop); + } + } + } + + // Function is public (callable from Start directly). + // - Always true for main + // - True for function addresses used as values + // - Otherwise false for stdlib or anonymous functions + // - Named functions use `!wholeWorld` + private static boolean funIsPublic( CodeGen code, boolean wholeWorld, FunNode fun ) { + // Always true for main + if( fun.sig().fidx() == code._main.fidx() ) return true; + // No escape analysis yet: a surviving address may be called from outside. + if( fun.hasPtr() ) return true; + // Never true for stdlib or anonymous functions + if( fun._name == null || fun._name.startsWith("sys.") ) + return false; + // Named functions (and not stdlib) are callable if not whole-world. + return !wholeWorld; + } + + // As part of building a CallGraph, when opto finds a function ptr flowing + // into a Call, link the Call and Fun. + private static void linkCG(CodeGen code, TypeFunPtr tfp, CallNode call) { + if( tfp.nargs() != call.nargs() ) return; // Error calls hit this + for( long fidxs=tfp.fidxs(); fidxs!=0; fidxs=TypeFunPtr.nextFIDX(fidxs) ) { + int fidx = Long.numberOfTrailingZeros(fidxs); + FunNode fun = code.link(fidx); + // null here means an external function; i.e. this Call + // calls to an outside library and all its arguments escape. + if( fun != null && !call.linked(fun) ) { + call.link( fun ); + code._iter.add(fun); + code._iter.addAll(fun._outputs); + } + } + } + + // The core SCCP algorithm + private static void sccp( CodeGen code, Ary<Type> oldTypes ) { + // Iter workList is empty at this point + // OPTIMISTIC PASS + Node n; + int count = 0; // Debug counter + while( (n = code._iter._work.pop()) != null ) { + if( n.isDead() ) continue; + count++; + Type oval = n._type, nval = n.compute(); + if( oval == nval ) continue; + assert oval.isa(nval); // Types start high and always fall + Type pesiVal = oldTypes.at(n._nid); + assert nval.isa(pesiVal); // Never fall worse than the pessimistic pass + n._type = nval; + + // If a TFP adds a new function input to a call, link to the new Fun + if( nval instanceof TypeFunPtr tfp ) { + for( Node use : n._outputs ) + if( !use._type.isHigh() && use instanceof CallNode call && call.fptr() == n ) + linkCG(code,tfp,call); + } + + // Link a Call which becomes alive + if( n instanceof CallNode call && oval.isHigh() && !nval.isHigh() && call.fptr()._type instanceof TypeFunPtr ) + linkCG(code,call.tfp(),call); + + // Since n._type changed, visit all output neighbors + code._iter.addAll(n._outputs); + n.moveDepsToWorklist(code._iter); + // Quadratic (expensive) small-step assert + assert check(code); + } + } + + // Quadratic (expensive) small-step assert + private static boolean check(CodeGen code) { + code._start.walk( x -> { + Type xval = x.compute(); + assert xval == x._type || (x._type.isa( xval ) && code._iter._work.on( x )); + return null; + }); + return true; + } + + // After SCCP add everything changed to the worklist and see if peepholes + // can make more progress. + private static void moveChangesToWorklist(CodeGen code, Ary<Type> oldTypes) { + code._start.walk( x -> { + assert x.compute() == x._type; // Hit the fixed point + assert x._nid >= oldTypes._len || x._type.isa(oldTypes.at(x._nid)); // Hit at least the bottom-up type + code._iter.add(x); + return null; + }); + } + + // Freeze field sizes; do struct layouts; convert field offsets into + // constants. + private static void fieldSizes( CodeGen code ) { + for( int i=0; i<code._start.nOuts(); i++ ) { + Node use = code._start.out(i); + if( use instanceof ConFldOffNode off ) { + TypeMemPtr tmp = (TypeMemPtr) Parser.TYPES.get(off._name); + off.subsume( off.asOffset(tmp._obj) ); + i--; + } + } + } + + // The remaining passes assume all calls are unlinked; i.e. we are throwing + // away the Call Graph here. Functions only reachable from internal calls + // need to be re-hooked to stop/start less they go dead. + private static void removeCallGraph(CodeGen code) { + code._start.walk( x -> { + // Unlink all existing (conservative) linkages. + if( x instanceof CallNode call ) { + for( Node y : call._outputs ) { + // Keep function alive and hooked to Start so it gets + // codegen'd. Function is callable by this call via + // TFP, although perhaps not by any other means. + if( y instanceof FunNode fun && !(fun.in(1) instanceof StartNode) ) { + ParmNode rpc = fun.rpc(); + if( rpc==null ) // Ensure valid RPC + rpc = makeRPC(fun); + // Insert a hook to Start and Stop + fun.insertDef(1,code._start); + for( Node use : fun._outputs ) + if( use instanceof ParmNode parm ) + parm.insertDef(1,ConstantNode.make(parm._type).peephole()); + code._stop.addDef(fun.ret()); + } + } + call.unlink_all(); + } + return null; + } ); + + } + + // Make a valid Parm RPC. + // First make sure a valid RPC; single-call into multi-fun will have each + // function having a single call site, so the RPC becomes a constant and + // folds - but since multiple targets, the Call never inlines. Recreate a + // valid RPC so codegen (and Eval2) understands the calling convention. + private static ParmNode makeRPC( FunNode fun ) { + ParmNode rpc = new ParmNode("$rpc",0,fun.ret().rpc()._type,fun); + for( int i=1; i<fun.nIns(); i++ ) { + CallEndNode cend = ((CallNode)fun.in(i)).cend(); + rpc.addDef(ConstantNode.make(cend._rpc).peephole()); + } + fun.ret().setDef(3,rpc.init()); + return rpc; + } + + +} diff --git a/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java b/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java index 6518f3b3..7e826661 100644 --- a/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java +++ b/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java @@ -60,6 +60,9 @@ public class RegAlloc { // ----------------------- // Live ranges with self-conflicts or no allowed registers private final IdentityHashMap<LRG,String> _failed = new IdentityHashMap<>(); + // Loop Phis get one chance to color after only cold self-conflict splits. + // If the same Phi self-conflicts again, split its hot def/backedge also. + private final IdentityHashMap<PhiNode,String> _deferredLoopSelf = new IdentityHashMap<>(); void fail( LRG lrg ) { assert lrg.leader(); _failed.put(lrg,""); @@ -341,6 +344,7 @@ public class RegAlloc { rclass.push(rmask); } + // Self conflicts require Phis (or two-address). // Insert a split after every def. boolean splitSelfConflict( byte round, LRG lrg ) { @@ -348,6 +352,19 @@ public class RegAlloc { Node[] conflicts = lrg._selfConflicts.keySet().toArray(new Node[0]); Arrays.sort(conflicts, (x,y) -> x._nid - y._nid ); + // First encounter with a loop Phi: try only cold splits this round. + // Remember the Phi across rounds so a persistent self-conflict forces + // the hot def/backedge splits on the next encounter. + IdentityHashMap<PhiNode,String> deferred = new IdentityHashMap<>(); + for( Node def : conflicts ) { + if( def instanceof PhiNode phi && phi.region() instanceof LoopNode ) + deferLoopSelf(phi,deferred); + for( Node use : def._outputs ) + if( use instanceof PhiNode phi && phi.region() instanceof LoopNode && + phi._inputs.find(def)==2 ) + deferLoopSelf(phi,deferred); + } + // For all conflicts for( Node def : conflicts ) { assert lrg(def)==lrg; // Might be conflict use-side @@ -356,6 +373,7 @@ public class RegAlloc { for( int i=0; i<def._outputs._len; i++ ) { Node use = def.out(i); if( (use instanceof PhiNode phi && + !(deferred.containsKey(phi) && phi.region() instanceof LoopNode && phi._inputs.find(def)==2) && !(phi.region() instanceof LoopNode loop && phi.in(2)==def && def.cfg0().idepth() > loop.idepth() ) ) || (use instanceof MachNode mach && mach.twoAddress()!=0 && use.in(mach.twoAddress())==def) ) insertBefore( use, use._inputs.find(def), "use/self/use",round,lrg ); @@ -364,11 +382,13 @@ public class RegAlloc { // shared with another Phi: otherwise the shared input keeps the // conflicting live ranges joined, even after splitting the entry. if( def instanceof PhiNode phi && !(def instanceof ParmNode) ) { - SplitNode split = makeSplit("def/self",round,lrg); - insertAfterAndReplace(split,def,false); - if( split.nOuts()==0 ) - split.killOrdered(); - for( int i=1; i<phi.nIns(); i++ ) + if( !deferred.containsKey(phi) ) { + SplitNode split = makeSplit("def/self",round,lrg); + insertAfterAndReplace(split,def,false); + if( split.nOuts()==0 ) + split.killOrdered(); + } + for( int i=1; i<(deferred.containsKey(phi) ? 2 : phi.nIns()); i++ ) if( i==1 || sharedPhiInput(phi,i) ) insertBefore(phi,i,"use/self/phi",round,lrg); } @@ -379,6 +399,13 @@ public class RegAlloc { return true; } + private void deferLoopSelf(PhiNode phi, IdentityHashMap<PhiNode,String> deferred) { + if( !_deferredLoopSelf.containsKey(phi) ) { + _deferredLoopSelf.put(phi,""); + deferred.put(phi,""); + } + } + private static boolean sharedPhiInput(PhiNode phi, int i) { for( Node use : phi.in(i)._outputs ) diff --git a/src/main/java/com/seaofnodes/simple/node/AddFNode.java b/src/main/java/com/seaofnodes/simple/node/AddFNode.java index fd713156..4ad02dbb 100644 --- a/src/main/java/com/seaofnodes/simple/node/AddFNode.java +++ b/src/main/java/com/seaofnodes/simple/node/AddFNode.java @@ -1,35 +1,29 @@ package com.seaofnodes.simple.node; - import com.seaofnodes.simple.type.Type; import com.seaofnodes.simple.type.TypeFloat; +import java.util.BitSet; -public class AddFNode extends Node { - public AddFNode(Node lhs, Node rhs) { super(null, lhs, rhs); } +public class AddFNode extends ArithFNode { + public AddFNode(Node lhs, Node rhs) { super(lhs, rhs); } @Override public String label() { return "AddF"; } - @Override protected String format() { return "(%1+%2)"; } + @Override public String glabel() { return "+"; } - @Override - public Type compute() { - if (in(1)._type instanceof TypeFloat i0 && - in(2)._type instanceof TypeFloat i1) { - if (i0.isConstant() && i1.isConstant()) - return TypeFloat.constant(i0.value()+i1.value()); - } - return in(1)._type.meet(in(2)._type); - } + @Override double doOp( double x, double y ) { return x+y; } @Override public Node idealize() { - Node lhs = in(1); - Type t2 = in(2)._type; - // Add of 0. + Type t2 = in(2)._type; if ( t2.isConstant() && t2 instanceof TypeFloat i && i.value()==0 ) - return lhs; + return in(1); + + // Move constants to RHS: con+arg becomes arg+con + if ( in(1)._type.isConstant() && !t2.isConstant() ) + return swap12(); return null; } diff --git a/src/main/java/com/seaofnodes/simple/node/AddNode.java b/src/main/java/com/seaofnodes/simple/node/AddNode.java index dfc7d7b3..2bbe1053 100644 --- a/src/main/java/com/seaofnodes/simple/node/AddNode.java +++ b/src/main/java/com/seaofnodes/simple/node/AddNode.java @@ -139,7 +139,7 @@ public class AddNode extends ArithNode { * dep can make progress. */ static PhiNode pcon(Node op, Node dep) { - return op instanceof PhiNode phi && phi.allCons(dep) ? phi : null; + return op instanceof PhiNode phi && !(phi instanceof ParmNode) && phi.allCons(dep) ? phi : null; } // Compare two off-spine nodes and decide what order they should be in. diff --git a/src/main/java/com/seaofnodes/simple/node/ArithFNode.java b/src/main/java/com/seaofnodes/simple/node/ArithFNode.java new file mode 100644 index 00000000..dafba626 --- /dev/null +++ b/src/main/java/com/seaofnodes/simple/node/ArithFNode.java @@ -0,0 +1,30 @@ +package com.seaofnodes.simple.node; + +import com.seaofnodes.print.ExprPrinter; + +import com.seaofnodes.simple.type.Type; +import com.seaofnodes.simple.type.TypeFloat; + +public abstract class ArithFNode extends Node { + public ArithFNode(Node lhs, Node rhs) { super(null, lhs, rhs); } + + @Override protected ExprPrinter<Node> _print1(ExprPrinter<Node> p) { + return p.open().n(in(1)).p(glabel()).n(in(2)).close(); + } + + abstract double doOp(double x, double y); + + @Override + public Type compute() { + Type t1 = in(1)._type, t2 = in(2)._type; + if( t1.isHigh() || t2.isHigh() ) + return Type.TOP; + if( t1 instanceof TypeFloat f1 && + t2 instanceof TypeFloat f2 ) { + if( f1.isConstant() && f2.isConstant() ) + return TypeFloat.constant(doOp(f1.value(),f2.value())); + } + return t1.meet(t2); + } + +} diff --git a/src/main/java/com/seaofnodes/simple/node/ArithNode.java b/src/main/java/com/seaofnodes/simple/node/ArithNode.java index 124acbd7..54290330 100644 --- a/src/main/java/com/seaofnodes/simple/node/ArithNode.java +++ b/src/main/java/com/seaofnodes/simple/node/ArithNode.java @@ -24,15 +24,15 @@ public abstract class ArithNode extends Node { // Generic airthmetic op math: high returns high; low returns low; 2 // constants fold; only 2 non-constants call specialized math. @Override - public final TypeInteger compute() { + public final Type compute() { Type t1 = in(1)._type, t2 = in(2)._type; if( t1.isHigh() || t2.isHigh() ) - return TypeInteger.TOP; + return Type.TOP; if( t1 instanceof TypeInteger x && t2 instanceof TypeInteger y ) return x.isConstant() && y.isConstant() ? con(x,y) - : doOp(x,y); + : doOp(x,y).makeWide( (byte)Math.max(x._widen,y._widen) ); return TypeInteger.BOT; } @@ -53,7 +53,7 @@ public abstract class ArithNode extends Node { if( in(1) instanceof PhiNode lhs && in(2) instanceof PhiNode rhs && lhs.nIns() >= 2 && !lhs.inProgress() && - lhs.region()==rhs.region() && + lhs.region()==rhs.region() && !(lhs.region() instanceof FunNode) && lhs.nIns()>2 && // A 1-input Phi will collapse already // Disallow with self-looping phi; these will collapse (lhs.in(2)!=lhs && rhs.in(2)!=rhs) ) { diff --git a/src/main/java/com/seaofnodes/simple/node/CProjNode.java b/src/main/java/com/seaofnodes/simple/node/CProjNode.java index 1225de31..c62de840 100644 --- a/src/main/java/com/seaofnodes/simple/node/CProjNode.java +++ b/src/main/java/com/seaofnodes/simple/node/CProjNode.java @@ -34,7 +34,7 @@ public class CProjNode extends CFGNode { @Override public Type compute() { Type t = ctrl()._type; - return t instanceof TypeTuple tt ? tt._types[_idx] : Type.BOTTOM; + return t instanceof TypeTuple tt ? tt._types[_idx] : (t.isHigh() ? Type.TOP : Type.BOTTOM); } @Override diff --git a/src/main/java/com/seaofnodes/simple/node/CallEndNode.java b/src/main/java/com/seaofnodes/simple/node/CallEndNode.java index e83e5cba..115f70c6 100644 --- a/src/main/java/com/seaofnodes/simple/node/CallEndNode.java +++ b/src/main/java/com/seaofnodes/simple/node/CallEndNode.java @@ -40,16 +40,23 @@ public class CallEndNode extends CFGNode implements MultiNode { @Override public Type compute() { - if( !(in(0) instanceof CallNode call) ) + if( !(in(0) instanceof CallNode call) || call._type != Type.CONTROL ) return TypeTuple.RET.dual(); - Type ret = Type.BOTTOM; - if( addDep(call.fptr())._type instanceof TypeFunPtr tfp ) { + // Mid-fold, just take the one single callers' return type + if( _folding ) return in(1)._type; + // Grab the TFP and use the functions declared return type. + Type ftype = addDep(call.fptr())._type; + Type ret = ftype.isHigh() ? Type.TOP : Type.BOTTOM; + if( ftype instanceof TypeFunPtr tfp ) { ret = tfp.ret(); // Here, if I can figure out I've found *all* callers, then I can meet // across the linked returns and join with the function return type. - if( tfp.isConstant() && nIns()>1 ) { - assert nIns()==2; // Linked exactly once for a constant - ret = ((TypeTuple)in(1)._type).ret(); // Return type + if( 1+tfp.nfcns() == nIns() ) { // A linked function for every concrete function + ret = Type.TOP; + for( int i=1; i<nIns(); i++ ) { + Type tret = in(i)._type instanceof TypeTuple rtt ? rtt.ret() : in(i)._type; + ret = ret.meet(tret); + } } } return TypeTuple.make(call._type,TypeMem.BOT,ret); @@ -73,12 +80,18 @@ public class CallEndNode extends CFGNode implements MultiNode { // Expecting Start, and the Call if( fun.nIns()==3 ) { assert fun.in(1) instanceof StartNode && fun.in(2)==call; - // Disallow self-recursive inlining (loop unrolling by another name) + // Disallow self-recursive inlining (loop unrolling by another name). + // Disallow if still folding other things, as it makes other + // dependency checks carry long chains of half-folded calls. + // Dead control may end the walk before an enclosing function. CFGNode idom = call; - while( !(idom instanceof FunNode) && idom!=null ) + while( idom!=null ) { idom = idom.idom(); + if( idom instanceof FunNode ) break; + if( idom instanceof CallEndNode cend && cend._folding ) break; + } // Inline? - if( idom != fun && idom != null ) { + if( idom instanceof FunNode fun2 && fun2 != fun && !fun2._folding ) { // Trivial inline: rewrite _folding = true; // Rewrite Fun so the normal RegionNode ideal collapses @@ -96,6 +109,8 @@ public class CallEndNode extends CFGNode implements MultiNode { // Bump the global version number invalidating them en-masse. CodeGen.CODE.invalidateIDepthCaches(); return this; + } else if( idom!=null ) { + addDep(idom); } } else { addDep(fun); diff --git a/src/main/java/com/seaofnodes/simple/node/CallNode.java b/src/main/java/com/seaofnodes/simple/node/CallNode.java index f66d1f71..e63b3f62 100644 --- a/src/main/java/com/seaofnodes/simple/node/CallNode.java +++ b/src/main/java/com/seaofnodes/simple/node/CallNode.java @@ -33,7 +33,7 @@ public class CallNode extends CFGNode { } public String name() { if( fptr()._type instanceof TypeFunPtr tfp && tfp._isConstant() && tfp.notNull() ) { - FunNode fun = CodeGen.CODE.link(tfp); + FunNode fun = CodeGen.CODE._link(tfp); if( fun !=null ) return fun._name; if( fptr() instanceof ExternNode ex ) return ex._extern; } @@ -115,16 +115,15 @@ public class CallNode extends CFGNode { } // True if Fun is linked to this Call - boolean linked( FunNode fun ) { + public boolean linked( FunNode fun ) { for( Node n : fun._inputs ) if( n == this ) return true; return false; } - // Link so this calls fun - private Node link( FunNode fun ) { + public Node link( FunNode fun ) { assert !linked(fun); fun.addDef(this); for( Node use : fun._outputs ) diff --git a/src/main/java/com/seaofnodes/simple/node/ConFldOffNode.java b/src/main/java/com/seaofnodes/simple/node/ConFldOffNode.java index 04b88b87..afdd29be 100644 --- a/src/main/java/com/seaofnodes/simple/node/ConFldOffNode.java +++ b/src/main/java/com/seaofnodes/simple/node/ConFldOffNode.java @@ -15,8 +15,8 @@ import com.seaofnodes.simple.util.SB; */ public class ConFldOffNode extends ConstantNode { - public final String _name; // Struct name - public final String _fname; // Field name + public final String _name; // Struct name + public final String _fname; // Field name public ConFldOffNode( String name, String fname ) { super(TypeInteger.BOT); _name = name; _fname = fname; } @Override public String label() { @@ -35,7 +35,7 @@ public class ConFldOffNode extends ConstantNode { @Override public boolean eq(Node n) { ConFldOffNode off = (ConFldOffNode)n; // Invariant - return _name==off._name && _fname==off._fname && super.eq(n); + return _name.equals(off._name) && _fname.equals(off._fname) && super.eq(n); } @Override int hash() { return super.hash() * _name.hashCode() * _fname.hashCode(); } } diff --git a/src/main/java/com/seaofnodes/simple/node/ConstantNode.java b/src/main/java/com/seaofnodes/simple/node/ConstantNode.java index 6384228e..7c330175 100644 --- a/src/main/java/com/seaofnodes/simple/node/ConstantNode.java +++ b/src/main/java/com/seaofnodes/simple/node/ConstantNode.java @@ -44,7 +44,7 @@ public class ConstantNode extends Node { @Override protected ExprPrinter<Node> _print1(ExprPrinter<Node> p) { if( _con instanceof TypeFunPtr tfp && tfp._isConstant() && tfp.notNull() ) { - FunNode fun = CodeGen.CODE.link(tfp); + FunNode fun = CodeGen.CODE._link(tfp); if( fun!=null && fun._name != null ) return p.p("{ ").p(fun._name).p("}"); } diff --git a/src/main/java/com/seaofnodes/simple/node/DivFNode.java b/src/main/java/com/seaofnodes/simple/node/DivFNode.java index 149499f9..0d037a30 100644 --- a/src/main/java/com/seaofnodes/simple/node/DivFNode.java +++ b/src/main/java/com/seaofnodes/simple/node/DivFNode.java @@ -1,26 +1,18 @@ package com.seaofnodes.simple.node; - import com.seaofnodes.simple.type.Type; import com.seaofnodes.simple.type.TypeFloat; +import java.util.BitSet; -public class DivFNode extends Node { - public DivFNode(Node lhs, Node rhs) { super(null, lhs, rhs); } +public class DivFNode extends ArithFNode { + public DivFNode(Node lhs, Node rhs) { super(lhs, rhs); } @Override public String label() { return "DivF"; } - @Override protected String format() { return "(%1/%2)"; } + @Override public String glabel() { return "/"; } - @Override - public Type compute() { - if (in(1)._type instanceof TypeFloat i0 && - in(2)._type instanceof TypeFloat i1) { - if (i0.isConstant() && i1.isConstant()) - return TypeFloat.constant(i0.value()/i1.value()); - } - return in(1)._type.meet(in(2)._type); - } + @Override double doOp( double x, double y ) { return x/y; } @Override public Node idealize() { diff --git a/src/main/java/com/seaofnodes/simple/node/FunNode.java b/src/main/java/com/seaofnodes/simple/node/FunNode.java index e7d6c3a6..70e1c200 100644 --- a/src/main/java/com/seaofnodes/simple/node/FunNode.java +++ b/src/main/java/com/seaofnodes/simple/node/FunNode.java @@ -91,14 +91,22 @@ public class FunNode extends RegionNode { // Only dead if no callers after SCCP if( unknownCallers() ) return Type.CONTROL; - return super.compute(); + Type t = Type.XCONTROL; + for (int i = 1; i < nIns(); i++) { + // Since no unknown callers, we are not main and the Start input + // will be a Tuple with XControl, so ignore it. Need to be called + // from someplace other than Start + if( !(in(i) instanceof StartNode) ) + t = t.meet(in(i)._type); + } + return t; } @Override public Node idealize() { - // Some linked path dies - Node progress = deadPath(); + // Some linked path dies, except main never kills Start + Node progress = deadPath(unknownCallers()); if( progress!=null ) { if( nIns()==3 && in(2) instanceof CallNode call ) CODE.add(call.cend()); // If Start and one call, check for inline @@ -106,8 +114,11 @@ public class FunNode extends RegionNode { } // Upgrade inferred or user-written return type to actual - if( _ret!=null && _ret._type instanceof TypeTuple tt && tt.ret() != _sig.ret() ) - throw Utils.TODO(); + if( _ret!=null && _ret._type instanceof TypeTuple tt && tt.ret() != _sig.ret() ) { + setSig(_sig.makeFrom(tt.ret())); + return this; + } + // When can we assume no callers? Or no other callers (except main)? // In a partial compilation, we assume Start gets access to any/all @@ -121,8 +132,10 @@ public class FunNode extends RegionNode { // to collapse if( unknownCallers() ) return null; - // If down to a single input, become that input - if( nIns()==2 && !hasPhi() ) { + // If folding (already inlined) down to a single input, become that input. + // Cannot collapse if not-inlining, and might not inline if call site + // calls multiple targets. + if( _folding && nIns()==2 && !hasPhi() ) { CODE.add( CODE._stop ); // Stop will remove dead path CODE.add( _ret ); // Return will compute to TOP control return in(1); // Collapse if no Phis; 1-input Phis will collapse on their own @@ -185,6 +198,14 @@ public class FunNode extends RegionNode { return in; } + // FunNodes must match signature (equivalent: no 2 FunNodes are ever GVN'able) + @Override public boolean eq( Node n ) { + return _sig == ((FunNode)n)._sig; + } + + @Override public int hash() { + return _sig.hashCode(); + } // ------------ // MachNode specifics, shared across all CPUs diff --git a/src/main/java/com/seaofnodes/simple/node/IfNode.java b/src/main/java/com/seaofnodes/simple/node/IfNode.java index da6a0cde..c96993e5 100644 --- a/src/main/java/com/seaofnodes/simple/node/IfNode.java +++ b/src/main/java/com/seaofnodes/simple/node/IfNode.java @@ -34,6 +34,7 @@ public class IfNode extends CFGNode implements MultiNode { @Override public Type compute() { // If the If node is not reachable then neither is any following Proj + assert !_inputs.isEmpty(); if (ctrl()._type != Type.CONTROL && ctrl()._type != Type.BOTTOM ) return TypeTuple.IF_NEITHER; Node pred = pred(); @@ -58,11 +59,15 @@ public class IfNode extends CFGNode implements MultiNode { // Hunt up the immediate dominator tree. If we find an identical if // test on either the true or false branch, that side wins. if( !pred()._type.isHighOrConst() ) - for( CFGNode dom = idom(), prior=this; dom!=null; prior = dom, dom = dom.idom() ) + for( CFGNode dom = idom(), prior=this; dom!=null; prior = dom, dom = dom.idom() ) { if( addDep(dom) instanceof IfNode iff && addDep(iff.pred())==pred() && prior instanceof CProjNode prj ) { setDef(1,con( prj._idx==0 ? 1 : 0 )); return this; } + if( dom instanceof RegionNode r ) + for( Node c : r._inputs ) + if( c!= null ) addDep(c); // If region loses input, idom changes + } return null; } diff --git a/src/main/java/com/seaofnodes/simple/node/LoadNode.java b/src/main/java/com/seaofnodes/simple/node/LoadNode.java index 06226df0..b3204cff 100644 --- a/src/main/java/com/seaofnodes/simple/node/LoadNode.java +++ b/src/main/java/com/seaofnodes/simple/node/LoadNode.java @@ -52,21 +52,32 @@ public class LoadNode extends MemOpNode { @Override public Type compute() { - if( ptr()._type==Type.TOP ) return Type.TOP; // Dead pointer, not a type error. - if( !(mem()._type instanceof TypeMem mem) ) - return _declaredType; // No memory yet? Declared type + Type tmem = mem()._type; + if( !(tmem instanceof TypeMem mem) ) + return tmem; // No memory yet? Assume TOP/BOT assert !_declaredType.isFRef(); // No lifting if ptr might null-check - if( err()!=null || !(ptr()._type instanceof TypeMemPtr tmp) ) - return _declaredType; // No pointer yet? Declared type - Type t = tmp._obj.field(_name)._t; - if( t instanceof TypeConAry ary ) { + Type tptr = ptr()._type; + if( err() != null ) + return _declaredType; + if( !(tptr instanceof TypeMemPtr tmp) ) + return tptr; // No pointer yet? Assume TOP/BOT + // Load field from object + Field f = tmp._obj.field(_name); + // No field? Open objects might yet get the field when falling; + // closed objects with missing field are an error. + if( f == null ) + return tmp.isHigh() ? Type.TOP : _declaredType; + Type t = f._t; + // Load member of constant array + if( t instanceof TypeConAry ary ) t = ary.elem(); // TODO: if offset is known, can peek the constant - } // Lift from declared type and memory input - t = t.join(_declaredType).join(MemMergeNode.contents(mem(),_alias,this)); + t = t.join(MemMergeNode.contents(mem(),_alias,this)); if( ptr()._type.isFinal() || _declaredType.isFinal() ) t = t.makeRO(); // Deep final applied + // Pinch between declared type + t = t.join(_declaredType); return t; } diff --git a/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java b/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java index 8d924b96..7a329117 100644 --- a/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java +++ b/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java @@ -45,6 +45,7 @@ public class MemMergeNode extends Node { if( mem instanceof ProjNode proj && proj.in(0) instanceof NewNode nnn ) { assert proj._idx==1 && nnn.field(alias)!=null; dep.addDep(nnn); + if( dep.addDep(nnn.in(0))._type.isHigh() ) return Type.TOP; return contents(nnn.mem(),alias,dep).meet(nnn.field(alias)._t.makeZero()); } // Function parameters and call results may contain arbitrary heap values. @@ -56,7 +57,6 @@ public class MemMergeNode extends Node { @Override public String label() { return "MemMerge"; } @Override public boolean isMem() { return true; } - @Override public Type compute() { return TypeMem.BOT; } @Override protected ExprPrinter<Node> _print1(ExprPrinter<Node> p) { p.p("MEM["); for( int i=1; i<nIns(); i++ ) @@ -67,6 +67,14 @@ public class MemMergeNode extends Node { return p.p("]"); } + + @Override public Type compute() { + for( Node n : _inputs ) + if( n != null && !n._type.isHigh() ) + return TypeMem.BOT; + return TypeMem.TOP; + } + @Override public Node idealize() { boolean progress=false, allDefault=true; for( int i=2; i<nIns(); i++ ) { diff --git a/src/main/java/com/seaofnodes/simple/node/MemPhiNode.java b/src/main/java/com/seaofnodes/simple/node/MemPhiNode.java index bada20ac..787333d9 100644 --- a/src/main/java/com/seaofnodes/simple/node/MemPhiNode.java +++ b/src/main/java/com/seaofnodes/simple/node/MemPhiNode.java @@ -21,11 +21,11 @@ public class MemPhiNode extends PhiNode { @Override public Type compute() { assert BulkMemPhiNode.checkMem(this,_alias); if( !(region() instanceof RegionNode r) ) - return region()._type==Type.XCONTROL ? TypeMem.TOP : _type; - if( r.inProgress() ) return _minType; + return (region()._type==Type.XCONTROL || region()._type==Type.TOP) ? TypeMem.TOP : _type; + if( r.inProgress() ) return r instanceof LoopNode ? _minType : TypeMem.BOT; Type t = Type.TOP; for( int i=1; i<nIns(); i++ ) - if( addDep(r.in(i))._type!=Type.XCONTROL ) + if( addDep(r.in(i))._type!=Type.XCONTROL && r.in(i)._type!=Type.TOP ) t = t.meet(MemMergeNode.contents(in(i),_alias,this)); return TypeMem.make(_alias,t); } diff --git a/src/main/java/com/seaofnodes/simple/node/MinusFNode.java b/src/main/java/com/seaofnodes/simple/node/MinusFNode.java index 852e646d..74439b8c 100644 --- a/src/main/java/com/seaofnodes/simple/node/MinusFNode.java +++ b/src/main/java/com/seaofnodes/simple/node/MinusFNode.java @@ -14,7 +14,8 @@ public class MinusFNode extends Node { @Override public Type compute() { - if (in(1)._type instanceof TypeFloat i0) + if( in(1)._type.isHigh() ) return TypeFloat.TOP; + if( in(1)._type instanceof TypeFloat i0) return i0.isConstant() ? TypeFloat.constant(-i0.value()) : i0; return TypeFloat.F64; } diff --git a/src/main/java/com/seaofnodes/simple/node/MinusNode.java b/src/main/java/com/seaofnodes/simple/node/MinusNode.java index 921e6066..94c69785 100644 --- a/src/main/java/com/seaofnodes/simple/node/MinusNode.java +++ b/src/main/java/com/seaofnodes/simple/node/MinusNode.java @@ -17,7 +17,7 @@ public class MinusNode extends Node { if( in(1)._type.isHigh() ) return TypeInteger.TOP; if( in(1)._type instanceof TypeInteger i0 && i0._min != Long.MIN_VALUE && i0._max != Long.MIN_VALUE ) - return TypeInteger.make(-i0._max,-i0._min); + return TypeInteger.make(-i0._max,-i0._min,i0._widen); return TypeInteger.BOT; } diff --git a/src/main/java/com/seaofnodes/simple/node/MulFNode.java b/src/main/java/com/seaofnodes/simple/node/MulFNode.java index 6a57f3c5..5c04af43 100644 --- a/src/main/java/com/seaofnodes/simple/node/MulFNode.java +++ b/src/main/java/com/seaofnodes/simple/node/MulFNode.java @@ -1,26 +1,18 @@ package com.seaofnodes.simple.node; - import com.seaofnodes.simple.type.Type; import com.seaofnodes.simple.type.TypeFloat; +import java.util.BitSet; -public class MulFNode extends Node { - public MulFNode(Node lhs, Node rhs) { super(null, lhs, rhs); } +public class MulFNode extends ArithFNode { + public MulFNode(Node lhs, Node rhs) { super(lhs, rhs); } @Override public String label() { return "MulF"; } - @Override protected String format() { return "(%1*%2)"; } + @Override public String glabel() { return "*"; } - @Override - public Type compute() { - if (in(1)._type instanceof TypeFloat i0 && - in(2)._type instanceof TypeFloat i1) { - if (i0.isConstant() && i1.isConstant()) - return TypeFloat.constant(i0.value()*i1.value()); - } - return in(1)._type.meet(in(2)._type); - } + @Override double doOp( double x, double y ) { return x*y; } @Override public Node idealize() { diff --git a/src/main/java/com/seaofnodes/simple/node/NewNode.java b/src/main/java/com/seaofnodes/simple/node/NewNode.java index 3c2a8de3..840d2759 100644 --- a/src/main/java/com/seaofnodes/simple/node/NewNode.java +++ b/src/main/java/com/seaofnodes/simple/node/NewNode.java @@ -5,6 +5,7 @@ import com.seaofnodes.print.ExprPrinter; import com.seaofnodes.simple.codegen.*; import com.seaofnodes.simple.type.*; import com.seaofnodes.simple.util.SB; +import com.seaofnodes.simple.util.Utils; /** Allocate a zeroed object. Inputs {ctrl, $mem, size}; @@ -45,7 +46,9 @@ public class NewNode extends Node implements MultiNode { @Override public TypeTuple compute() { - return TypeTuple.make(_ptr,TypeMem.BOT); + return in(0)._type.isHigh() + ? TypeTuple.make(_ptr.makeHigh(),TypeMem.TOP) + : TypeTuple.make(_ptr,TypeMem.BOT); } @Override diff --git a/src/main/java/com/seaofnodes/simple/node/Node.java b/src/main/java/com/seaofnodes/simple/node/Node.java index 3eacbb16..414530b4 100644 --- a/src/main/java/com/seaofnodes/simple/node/Node.java +++ b/src/main/java/com/seaofnodes/simple/node/Node.java @@ -2,6 +2,7 @@ package com.seaofnodes.simple.node; import com.seaofnodes.print.BaseNode; +import com.seaofnodes.simple.IterPeeps; import com.seaofnodes.simple.Parser; import com.seaofnodes.simple.util.Ary; import com.seaofnodes.simple.util.Utils; @@ -154,9 +155,9 @@ public abstract class Node extends BaseNode<Node> implements Cloneable { } // Insert the numbered input, sliding other inputs to the right - Node insertDef(int idx, Node new_def) { - _inputs.add(idx,null); - return setDef(idx,new_def); + public void insertDef(int idx, Node new_def) { + _inputs.insert(null,idx); + setDef(idx,new_def); } /** @@ -182,7 +183,7 @@ public abstract class Node extends BaseNode<Node> implements Cloneable { // Remove node 'use' from 'def's (i.e. our) output list, by compressing the list in-place. // Return true if the output list is empty afterward. // Error is 'use' does not exist; ok for 'use' to be null. - protected boolean delUse( Node use ) { + public boolean delUse( Node use ) { _outputs.del(_outputs.find(use)); moveDepsToWorklist(); // User-count and anti-dependence queries can now change. return _outputs.isEmpty(); @@ -213,8 +214,11 @@ public abstract class Node extends BaseNode<Node> implements Cloneable { while( nIns()>0 ) { // Set all inputs to null, recursively killing unused Nodes Node old_def = _inputs.removeLast(); // Revisit neighbor because removed use - if( old_def != null && CODE.add(old_def).delUse(this) ) - old_def.kill(); // If we removed the last use, the old def is now dead + if( old_def != null ) { + if( CODE.add(old_def).delUse(this) ) + old_def.kill(); // If we removed the last use, the old def is now dead + old_def.moveDepsToWorklist(); // Use-count changes can enable distant rewrites. + } } assert isDead(); // Really dead now } @@ -431,7 +435,7 @@ public abstract class Node extends BaseNode<Node> implements Cloneable { // If changing, add users to worklist. public Type setType(Type type) { Type old = _type; - assert old==null || type.isa(old); // Since _type not set, can just re-run this in assert in the debugger + assert old == null || type.isa(old) : "Monotonicity test failed"; if( old == type ) return old; _type = type; // Set _type late for easier assert debugging CODE.addAll(_outputs); @@ -499,7 +503,7 @@ public abstract class Node extends BaseNode<Node> implements Cloneable { public Node dep(int idx) { return _deps.get(idx); } /** - * Add a node to the list of dependencies. Only add it if its not an input + * Add a node to the list of dependencies. Only add it if it's not an input * or output of this node, that is, it is at least one step away. The node * being added must benefit from this node being peepholed. */ @@ -523,9 +527,10 @@ public abstract class Node extends BaseNode<Node> implements Cloneable { } // Move the dependents onto a worklist, and clear for future dependents. - public void moveDepsToWorklist( ) { - if( _deps==null ) return; - CODE.addAll(_deps); + public void moveDepsToWorklist( ) { moveDepsToWorklist(CODE._iter); } + public void moveDepsToWorklist( IterPeeps iter ) { + if( _deps == null ) return; + iter.addAll(_deps); _deps.clear(); } diff --git a/src/main/java/com/seaofnodes/simple/node/ParmNode.java b/src/main/java/com/seaofnodes/simple/node/ParmNode.java index 8b614624..95934e4b 100644 --- a/src/main/java/com/seaofnodes/simple/node/ParmNode.java +++ b/src/main/java/com/seaofnodes/simple/node/ParmNode.java @@ -2,7 +2,9 @@ package com.seaofnodes.simple.node; import com.seaofnodes.print.ExprPrinter; +import com.seaofnodes.simple.Parser; import com.seaofnodes.simple.type.Type; +import com.seaofnodes.simple.type.TypeMemPtr; public class ParmNode extends PhiNode { @@ -32,6 +34,25 @@ public class ParmNode extends PhiNode { // Always in-progress until we run out of unknown callers @Override public boolean inProgress() { return in(0) instanceof FunNode fun && fun.inProgress(); } + @Override + public Node idealize() { + if( !(region() instanceof FunNode) ) + return in(1); // Input has collapse to e.g. starting control. + // If function is folding, do all possible peeps + if( fun()._folding ) return super.idealize(); + + // Can upgrade minType even while in-progress + if( _minType instanceof TypeMemPtr tmp && _minType.isFRef() ) { + TypeMemPtr tmp2 = (TypeMemPtr) Parser.TYPES.get(tmp._obj._name); + if( tmp2!=null && tmp2 != _minType ) { + _minType = tmp2; + return this; + } + } + // Skip most phi optimizations on parms + return null; + } + @Override public boolean eq( Node n ) { return ((ParmNode)n)._idx==_idx && super.eq(n); } diff --git a/src/main/java/com/seaofnodes/simple/node/PhiNode.java b/src/main/java/com/seaofnodes/simple/node/PhiNode.java index af5d900b..6cfeecfe 100644 --- a/src/main/java/com/seaofnodes/simple/node/PhiNode.java +++ b/src/main/java/com/seaofnodes/simple/node/PhiNode.java @@ -15,6 +15,8 @@ public class PhiNode extends Node { // Int stays Int, Ptr stays Ptr, Control stays Control, Mem stays Mem. Type _minType; + int lattice_drop; + public PhiNode(String label, Type minType, Node... inputs) { super(inputs); _label = label; @@ -51,26 +53,44 @@ public class PhiNode extends Node { public CFGNode region() { return (CFGNode)in(0); } @Override public boolean isMem() { return _minType instanceof TypeMem; } + boolean isRPC() { return false; } @Override public Type compute() { if( !(region() instanceof RegionNode r) ) - return region()._type==Type.XCONTROL ? (_type instanceof TypeMem ? TypeMem.TOP : Type.TOP) : _type; + return region()._type==Type.XCONTROL || region()._type==Type.TOP ? (_type instanceof TypeMem ? TypeMem.TOP : Type.TOP) : _type; // During parsing Phis have to be computed type pessimistically. - if( r.inProgress() ) return _minType; + if( r.inProgress() || in(nIns()-1)==null ) + // Loop-Phis must lift to the declared type, because that is how + // the Parser keeps precise types until the loop finishes parsing. + // Similar, ParmNodes use precise minType until all calls are + // linked (post opto). + return r instanceof LoopNode || (this instanceof ParmNode) ? _minType : Type.BOTTOM; // Set type to local top of the starting type - //Type t = _minType.dual(); Type t = Type.TOP; - for (int i = 1; i < nIns(); i++) + for (int i = 1; i < nIns(); i++) { // If the region's control input is live, add this as a dependency // to the control because we can be peeped should it become dead. - if( addDep(r.in(i))._type != Type.XCONTROL ) { + Type ctrl = addDep(r.in(i))._type; + if( ctrl != Type.XCONTROL && ctrl != Type.TOP ) { if( in(i)._type==Type.BOTTOM ) return Type.BOTTOM; t = t.meet(in(i)._type); } - t = t.join( _minType ); - return t; + } + Type newt = t.join( _minType ); + + // Above-center ranges may still fall to unwidened constants. + // Widen only below-center ranges to preserve monotonicity. + if( region() instanceof LoopNode && // Only around loops + newt instanceof TypeInteger newi && + // Types changed and are falling (the optimistic case, expected to fall forever) + newi != _type ) { + if( !newi.isHigh() && !newi.isConstant() && (!(_type instanceof TypeInteger oldi) || newi._widen <= oldi._widen) ) + return newi.same_but_slightly_wider_than(_minType); + } + + return newt; } @Override @@ -79,7 +99,7 @@ public class PhiNode extends Node { return in(1); // Input has collapse to e.g. starting control. // Can upgrade minType even while in-progress if( _minType instanceof TypeMemPtr tmp && _minType.isFRef() ) { - TypeMemPtr tmp2 = (TypeMemPtr)CodeGen.CODE.P.TYPES.get(tmp._obj._name); + TypeMemPtr tmp2 = (TypeMemPtr) Parser.TYPES.get(tmp._obj._name); if( tmp2!=null && tmp2._obj != tmp._obj ) { _minType = tmp.makeFrom(tmp2._obj); return this; @@ -124,13 +144,14 @@ public class PhiNode extends Node { Node val = in(3-nullx); if( val instanceof CastNode cast ) val = cast.in(1); - if( addDep(r.idom(this)) instanceof IfNode iff && addDep(iff.pred())==val ) { + Node ridom = r.idom(this); + if( ridom instanceof IfNode iff && addDep(iff.pred())==val ) { // Must walk the idom on the null side to make sure we hit False. CFGNode idom = (CFGNode)r.in(nullx); while( idom != null && idom.nIns() > 0 && idom.in(0) != iff ) idom = idom.idom(); if( idom instanceof CProjNode proj && proj._idx==1 ) return val; - } + } else if( ridom != null ) addDep(ridom); } } diff --git a/src/main/java/com/seaofnodes/simple/node/ProjNode.java b/src/main/java/com/seaofnodes/simple/node/ProjNode.java index 26b3a522..92c6c2be 100644 --- a/src/main/java/com/seaofnodes/simple/node/ProjNode.java +++ b/src/main/java/com/seaofnodes/simple/node/ProjNode.java @@ -41,7 +41,7 @@ public class ProjNode extends Node { @Override public Type compute() { Type t = in(0)._type; - return t instanceof TypeTuple tt ? tt._types[_idx] : Type.BOTTOM; + return t instanceof TypeTuple tt ? tt._types[_idx] : t.oob(); } @Override public Node idealize() { return ((MultiNode)in(0)).pcopy(_idx); } diff --git a/src/main/java/com/seaofnodes/simple/node/RegionNode.java b/src/main/java/com/seaofnodes/simple/node/RegionNode.java index 72f0df7e..59030dee 100644 --- a/src/main/java/com/seaofnodes/simple/node/RegionNode.java +++ b/src/main/java/com/seaofnodes/simple/node/RegionNode.java @@ -38,7 +38,7 @@ public class RegionNode extends CFGNode { public Node idealize() { if( inProgress() ) return null; - Node progress = deadPath(); + Node progress = deadPath(false); if( progress!=null ) return progress; // If down to a single input, become that input @@ -84,16 +84,21 @@ public class RegionNode extends CFGNode { return null; } - Node deadPath() { + Node deadPath(boolean skipStart) { // Delete dead paths into a Region - int path = findDeadInput(); + int path = findDeadInput(skipStart ? 2 :1); if( path==0 ) return null; + // Do not delete the entry path of a loop (ok to remove the back edge // and make the loop a single-entry Region which folds away the Loop). // Folding the entry path confused the loop structure, moving the // backedge to the entry point. if( this instanceof LoopNode loop && loop.entry()==in(path) ) return null; + return removeDeadPath(path); + } + + public Node removeDeadPath(int path) { // Cannot use the obvious output iterator here, because a Phi deleting // an input might recursively delete *itself*. This shuffles the // output array, and we might miss iterating an unrelated Phi. So on @@ -102,15 +107,16 @@ public class RegionNode extends CFGNode { while( nouts != nOuts() ) { nouts = nOuts(); for( int i=0; i<nOuts(); i++ ) - if( out(i) instanceof PhiNode phi && phi.nIns()==nIns() ) + if( out(i) instanceof PhiNode phi && phi.nIns()==nIns() ) { + CodeGen.CODE.addAll(phi.in(path)._outputs); CodeGen.CODE.addAll(phi.delDef(path)._outputs); + } } return isDead() ? Parser.XCTRL : delDef(path); } - - private int findDeadInput() { - for( int i=1; i<nIns(); i++ ) + private int findDeadInput(int startIdx) { + for( int i=startIdx; i<nIns(); i++ ) if( in(i)._type==Type.XCONTROL ) return i; return 0; // All inputs alive @@ -131,10 +137,10 @@ public class RegionNode extends CFGNode { if( use instanceof PhiNode ) { for( Node data : use._outputs ) { if( !(data instanceof PhiNode phi2) || phi2.region()!=this ) - { addDep(use); if( data!=null ) addDep(data); return true; } + { addDep(use); if( data!=null ) addDep(data); return true; } } } else - { addDep(use); return true; } // Control user + { addDep(use); return true; } // Control user } return false; } @@ -154,7 +160,8 @@ public class RegionNode extends CFGNode { CFGNode lca = null; // Recompute from predecessors: CFG edits can change the dominator. for( int i=1; i<nIns(); i++ ) - lca = cfg(i).domLCA(lca,dep); + if( !cfg(i)._type.isHigh() ) + lca = cfg(i).domLCA(lca,dep); return lca; } diff --git a/src/main/java/com/seaofnodes/simple/node/ReturnNode.java b/src/main/java/com/seaofnodes/simple/node/ReturnNode.java index 6d268994..266657be 100644 --- a/src/main/java/com/seaofnodes/simple/node/ReturnNode.java +++ b/src/main/java/com/seaofnodes/simple/node/ReturnNode.java @@ -108,12 +108,17 @@ public class ReturnNode extends CFGNode { } @Override public Parser.ParseException err() { - return expr()._type==Type.BOTTOM ? mixerr(ti,tf,tp,tn,_fun._loc) : null; + if( ctrl()._type != Type.CONTROL ) return null; // Exit path is dead + return expr()._type==Type.BOTTOM || expr()._type==Type.TOP ? mixerr(ti,tf,tp,tn,_fun._loc) : null; } static Parser.ParseException mixerr( boolean ti, boolean tf, boolean tp, boolean tn, Parser.Lexer loc ) { if( !ti && !tf && !tp && !tn ) + // Hit when the function never returns. e.g. `f = { -> return f() };` return Parser.error("No defined return type", loc); + // Rather ugly way to print conflicting return types + int cnt = (ti?1:0) + (tf?1:0) + (tp||tn?1:0); + if( cnt==1 ) return null; // Uniform return type, something else errored and will report SB sb = new SB().p("No common type amongst "); if( ti ) sb.p("int and "); if( tf ) sb.p("f64 and "); diff --git a/src/main/java/com/seaofnodes/simple/node/StoreNode.java b/src/main/java/com/seaofnodes/simple/node/StoreNode.java index 603a0607..4e1d7ce3 100644 --- a/src/main/java/com/seaofnodes/simple/node/StoreNode.java +++ b/src/main/java/com/seaofnodes/simple/node/StoreNode.java @@ -165,7 +165,7 @@ public class StoreNode extends MemOpNode { Parser.ParseException err = super.err(); if( err != null ) return err; if( ptr()._type == Type.TOP ) - return null; // Dead store + return null; // This means we have an error input, report elsewhere TypeMemPtr tmp = (TypeMemPtr)ptr()._type; if( (tmp._ro || tmp._obj.field(_name)._final) && !_init ) return Parser.error("Cannot modify final field '"+_name+"'",_loc); diff --git a/src/main/java/com/seaofnodes/simple/node/SubFNode.java b/src/main/java/com/seaofnodes/simple/node/SubFNode.java index 2d218a03..3fc4f7ca 100644 --- a/src/main/java/com/seaofnodes/simple/node/SubFNode.java +++ b/src/main/java/com/seaofnodes/simple/node/SubFNode.java @@ -1,35 +1,25 @@ package com.seaofnodes.simple.node; - import com.seaofnodes.simple.type.Type; import com.seaofnodes.simple.type.TypeFloat; +import java.util.BitSet; -public class SubFNode extends Node { - public SubFNode(Node lhs, Node rhs) { super(null, lhs, rhs); } +public class SubFNode extends ArithFNode { + public SubFNode(Node lhs, Node rhs) { super(lhs, rhs); } @Override public String label() { return "SubF"; } - @Override protected String format() { return "(%1-%2)"; } + @Override public String glabel() { return "-"; } - @Override - public Type compute() { - if (in(1)._type instanceof TypeFloat i0 && - in(2)._type instanceof TypeFloat i1) { - if (i0.isConstant() && i1.isConstant()) - return TypeFloat.constant(i0.value()-i1.value()); - } - return in(1)._type.meet(in(2)._type); - } + @Override double doOp( double x, double y ) { return x-y; } @Override public Node idealize() { - Node lhs = in(1); - Type t2 = in(2)._type; - // Sub of 0. + Type t2 = in(2)._type; if ( t2.isConstant() && t2 instanceof TypeFloat i && i.value()==0 ) - return lhs; + return in(1); return null; } diff --git a/src/main/java/com/seaofnodes/simple/node/ToFloatNode.java b/src/main/java/com/seaofnodes/simple/node/ToFloatNode.java index 7b0122ce..840a95ec 100644 --- a/src/main/java/com/seaofnodes/simple/node/ToFloatNode.java +++ b/src/main/java/com/seaofnodes/simple/node/ToFloatNode.java @@ -15,12 +15,10 @@ public class ToFloatNode extends Node { @Override public Type compute() { + if( in(1)._type.isHigh() ) return TypeFloat.F64.dual(); if( in(1)._type == Type.NIL ) return TypeFloat.FZERO; - if (in(1)._type instanceof TypeInteger i0 ) { - if( i0.isHigh() ) return TypeFloat.F64.dual(); - if( i0.isConstant() ) - return TypeFloat.constant(i0.value()); - } + if( in(1)._type instanceof TypeInteger i0 && i0.isConstant() ) + return TypeFloat.constant(i0.value()); return TypeFloat.F64; } diff --git a/src/main/java/com/seaofnodes/simple/node/cpus/arm/SetARM.java b/src/main/java/com/seaofnodes/simple/node/cpus/arm/SetARM.java index 1cda4787..afbbd3bf 100644 --- a/src/main/java/com/seaofnodes/simple/node/cpus/arm/SetARM.java +++ b/src/main/java/com/seaofnodes/simple/node/cpus/arm/SetARM.java @@ -21,6 +21,7 @@ public class SetARM extends MachConcreteNode implements MachNode { @Override public RegMask outregmap() { return arm.WMASK; } @Override public void encoding( Encoding enc ) { + // Using RM==RN==31 implies a *zero* value, not R31. int body = Arm64.cset(Arm64.OP_CSET,0b11111, Arm64.make_condition(_bop), 0b011111, enc.reg(this)); enc.add4(body); } diff --git a/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java b/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java index 9faf1d40..32c1e2fc 100644 --- a/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java +++ b/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java @@ -239,7 +239,9 @@ public class arm extends Machine { if( idx-2-fcnt < cargs.length ) return cargs[idx-2-fcnt]; } - throw Utils.TODO(); // Pass on stack slot + // Pass on stack slot (8 and higher) + if( maxArgSlot>0 ) throw Utils.TODO(); + return new RegMask(MAX_REG + 1 + (idx - 2)); } // Return the max stack slot used by this signature, or 0 diff --git a/src/main/java/com/seaofnodes/simple/node/cpus/riscv/MemOpRISC.java b/src/main/java/com/seaofnodes/simple/node/cpus/riscv/MemOpRISC.java index 22dba099..adf21848 100644 --- a/src/main/java/com/seaofnodes/simple/node/cpus/riscv/MemOpRISC.java +++ b/src/main/java/com/seaofnodes/simple/node/cpus/riscv/MemOpRISC.java @@ -50,6 +50,9 @@ public abstract class MemOpRISC extends MemOpNode implements MachNode { if( _declaredType == TypeInteger.BOOL) func3=4; // LBU if( _declaredType == TypeInteger.U16 ) func3=5; // LHU if( _declaredType == TypeInteger.U32 ) func3=6; // LWU + if( _declaredType instanceof TypeInteger ti ) { + if( -128 <= ti._min && ti._max < 128 ) func3 = 0; // LB + } // float if( _declaredType == TypeFloat.F32) func3 = 2; // fLW fSW diff --git a/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/SetX86.java b/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/SetX86.java index 533d5652..864c1b55 100644 --- a/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/SetX86.java +++ b/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/SetX86.java @@ -30,6 +30,7 @@ public class SetX86 extends MachConcreteNode implements MachNode { case "<" -> _unsigned ? 0x92 : 0x9C; // SETB /SETL case "<=" -> _unsigned ? 0x96 : 0x9E; // SETBE/SETLE case ">=" -> _unsigned ? 0x93 : 0x9D; // SETAE/SETGE + case ">" -> _unsigned ? 0x97 : 0x9F; // SETA /SETG default -> throw Utils.TODO(); }; X86.set(enc,op&15,enc.reg(this)); diff --git a/src/main/java/com/seaofnodes/simple/print/SimpleGraphAdapter.java b/src/main/java/com/seaofnodes/simple/print/SimpleGraphAdapter.java index 785049dc..8dc6ea47 100644 --- a/src/main/java/com/seaofnodes/simple/print/SimpleGraphAdapter.java +++ b/src/main/java/com/seaofnodes/simple/print/SimpleGraphAdapter.java @@ -6,7 +6,7 @@ import com.seaofnodes.simple.node.*; import com.seaofnodes.simple.node.Node; import com.seaofnodes.simple.type.TypeMem; -/** Chapter 23's view of the IR; browser, transport and layout are shared. */ +/** Chapter 24's view of the IR; browser, transport and layout are shared. */ public class SimpleGraphAdapter extends GraphAdapter<Node> { @Override protected String edgeName(Node n, int i) { diff --git a/src/main/java/com/seaofnodes/simple/print/SimpleGraphObserver.java b/src/main/java/com/seaofnodes/simple/print/SimpleGraphObserver.java index 8877b310..3df1e0ea 100644 --- a/src/main/java/com/seaofnodes/simple/print/SimpleGraphObserver.java +++ b/src/main/java/com/seaofnodes/simple/print/SimpleGraphObserver.java @@ -7,7 +7,7 @@ import com.seaofnodes.simple.node.Node; import java.util.ArrayList; import java.io.IOException; -/** Chapter 23's compilation context; capture and event bookkeeping are shared. */ +/** Chapter 24's compilation context; capture and event bookkeeping are shared. */ public class SimpleGraphObserver extends GraphCapture<Node> { private CodeGen _code; public SimpleGraphObserver() { super(new SimpleGraphAdapter()); } diff --git a/src/main/java/com/seaofnodes/simple/type/Type.java b/src/main/java/com/seaofnodes/simple/type/Type.java index 3f115c3f..b9a6a1f3 100644 --- a/src/main/java/com/seaofnodes/simple/type/Type.java +++ b/src/main/java/com/seaofnodes/simple/type/Type.java @@ -264,6 +264,9 @@ public class Type /*implements Cloneable*/ { // Reverse; xmeet 2nd arg is never "is_simple" and never equal to "this". if( is_simple() ) return this.xmeet(t ); if( t.is_simple() ) return t .xmeet(this); + // Constant arrays meet their integer element types. + if( this instanceof TypeConAry tcon && t instanceof TypeInteger ti ) return tcon.ymeet(ti); + if( t instanceof TypeConAry tcon && this instanceof TypeInteger ti ) return tcon.ymeet(ti); return Type.BOTTOM; // Mixing 2 unrelated types } @@ -316,7 +319,8 @@ public class Type /*implements Cloneable*/ { } // True if this "isa" t; e.g. 17 isa TypeInteger.BOT - public boolean isa( Type t ) { return meet(t)==t; } + // Applies for pessimistic case + public boolean isa( Type t ) { return meet(t)==t; } // True if this "isa" t up to named structures public boolean shallowISA( Type t ) { return isa(t); } @@ -333,6 +337,9 @@ public class Type /*implements Cloneable*/ { // Is forward-reference public boolean isFRef() { return false; } + // Cap at limits + public Type oob() { return isHigh() ? TOP : BOTTOM; } + // ---------------------------------------------------------- // Cyclic types! Flag the start of a cyclic type by putting a sentinel in @@ -481,6 +488,7 @@ public class Type /*implements Cloneable*/ { Type _glb(boolean mem) { assert is_simple(); return Type.BOTTOM; } Type _close() { return this; } + public Type widen() { return this; } // ---------------------------------------------------------- diff --git a/src/main/java/com/seaofnodes/simple/type/TypeConAry.java b/src/main/java/com/seaofnodes/simple/type/TypeConAry.java index 84cccd12..0bc264fc 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeConAry.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeConAry.java @@ -1,56 +1,62 @@ package com.seaofnodes.simple.type; -import com.seaofnodes.simple.util.Utils; import java.io.ByteArrayOutputStream; +import com.seaofnodes.simple.util.Utils; import java.util.ArrayList; /** * Represents a constant array of primitives */ -public class TypeConAry<A> extends Type { +public abstract class TypeConAry<A> extends Type { boolean _any; - // One of byte,short,int,long,float,double array + byte _widen; + // One of byte or int array public final A _ary; - TypeConAry( boolean any, A ary ) { super(TINT); _any = any; _ary = ary; } - public static final TypeConAry BOT = new TypeConAry(false,null).intern(); + TypeConAry( boolean any, byte widen, A ary ) { super(TCONARY); _any = any; _widen = widen; _ary = ary; } public static void gather(ArrayList<Type> ts) { - ts.add(BOT); ts.add(TypeConAryB.ABC); ts.add(TypeConAryB.ABCD); ts.add(TypeConAryI.I123); } + // Fresh, uninterned type sharing this array; xdual must not intern. + abstract TypeConAry<A> _make(boolean any, byte widen); - @Override public String str() { return (_any?"~":"") + "[]"; } - @Override TypeConAry xdual() { - if( _ary==null ) - return new TypeConAry(!_any,null); - return this; - } + @Override TypeConAry<A> xdual() { return _make( !_any, (byte)(3-_widen) ); } @Override Type xmeet(Type t) { - if( t instanceof TypeInteger ti ) return imeet(ti); TypeConAry ary = (TypeConAry)t; // Invariant - if( this==BOT ) return BOT; - if( ary ==BOT ) return BOT; - if( this==BOT.dual() ) return ary ; - if( ary ==BOT.dual() ) return this; - assert _ary!=ary._ary; // Already interned and this!=t + // Same base array but different? + if( _equals(ary) ) + // Return array with larger widen + return _widen >= ary._widen ? this : ary; + // Unrelated constant arrays, falls to some int range return elem().meet(ary.elem()); } - Type imeet( TypeInteger ti ) { - if( this==BOT.dual() ) return ti; - if( this==BOT ) return BOT; - Type elem = elem(); - if( !(elem instanceof TypeInteger) ) return BOTTOM; - if( ti.isHigh() && elem.isa(ti.dual()) ) - return this; - return elem.meet(ti); + + Type ymeet( TypeInteger ti ) { + // if i can isa *each* element, then maybe can keep. + // no good to i.isa(elem()) because fails the dual + for( int j=0; j<len(); j++ ) + if( !ti.isa(TypeInteger.make(at8(j),at8(j),ti._widen)) ) + return ti.meet(elem()); + byte widen = (byte)Math.max(_widen,ti._widen); + return widen==_widen ? this : _make(_any,widen).intern(); } + private boolean _equals(TypeConAry ary) { + int len = len(); + if( len != ary.len() ) return false; + for( int i=0; i<len; i++ ) + if( at8(i) != ary.at8(i) ) + return false; + return true; + } @Override public boolean isHigh() { return this==TOP; } @Override boolean _isConstant() { return true; } + @Override Type _glb(boolean mem) { return this; } + @Override boolean _isGLB(boolean mem) { return true; } // Meet-over-elements type public Type elem() { @@ -63,20 +69,11 @@ public class TypeConAry<A> extends Type { min = Math.min(min,at8(i)); max = Math.max(max,at8(i)); } - return TypeInteger.make(min,max); - } - public long at8(int idx) { throw Utils.TODO(); } - public int len() { throw Utils.TODO(); } - @Override public int log_size() { throw Utils.TODO(); } - public void write( ByteArrayOutputStream baos ) { throw Utils.TODO(); } - - @Override boolean eq(Type t) { - return t instanceof TypeConAry ary && _any==ary._any && ary._ary==null; - } - - @Override int hash() { - assert _ary==null; - return _any ? 1024 : 0; + return TypeInteger.make(min,max,_widen); } + public abstract long at8(int idx); + public abstract int len(); + @Override public abstract int log_size(); + public void write( ByteArrayOutputStream baos ) { throw Utils.TODO("Should not reach here: abstract constant array cannot be written"); } } diff --git a/src/main/java/com/seaofnodes/simple/type/TypeConAryB.java b/src/main/java/com/seaofnodes/simple/type/TypeConAryB.java index 75f08bef..095cdeca 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeConAryB.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeConAryB.java @@ -1,11 +1,12 @@ package com.seaofnodes.simple.type; -import java.util.Arrays; import java.io.ByteArrayOutputStream; +import java.util.Arrays; public class TypeConAryB extends TypeConAry<byte[]> { - private TypeConAryB(byte[] bs) { super(false,bs); } - public static TypeConAryB make( byte[] bs ) { return new TypeConAryB(bs).intern(); } + private TypeConAryB(boolean any, byte widen, byte[] bs) { super(any,widen,bs); } + @Override TypeConAryB _make( boolean any, byte widen ) { return new TypeConAryB(any,widen,_ary); } + public static TypeConAryB make( byte[] bs ) { return new TypeConAryB(false,(byte)0,bs).intern(); } public static TypeConAryB make( String s ) { return make(s.getBytes()); } static final TypeConAryB ABC = make("abc"); static final TypeConAryB ABCD = make("abcd"); @@ -13,7 +14,7 @@ public class TypeConAryB extends TypeConAry<byte[]> { @Override public int len() { return _ary.length; } @Override public int log_size() { return 0; } @Override public String str() { return "[\""+new String(_ary)+"\"]"; } - @Override boolean eq(Type t) { return t instanceof TypeConAryB ary && Arrays.equals(_ary,ary._ary); } + @Override boolean eq(Type t) { return t instanceof TypeConAryB ary && _widen==ary._widen && Arrays.equals(_ary,ary._ary); } @Override int hash() { return Arrays.hashCode(_ary); } @Override public void write( ByteArrayOutputStream baos ) { baos.write(_ary,0,_ary.length); } } diff --git a/src/main/java/com/seaofnodes/simple/type/TypeConAryI.java b/src/main/java/com/seaofnodes/simple/type/TypeConAryI.java index 577de82c..b1b061de 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeConAryI.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeConAryI.java @@ -3,13 +3,14 @@ package com.seaofnodes.simple.type; import java.util.Arrays; public class TypeConAryI extends TypeConAry<int[]> { - private TypeConAryI(int[] bs) { super(false,bs); } - public static TypeConAryI make( int[] bs ) { return new TypeConAryI(bs).intern(); } - static final TypeConAryI I123 = make(new int[]{1,2,3}); + private TypeConAryI(boolean any, byte widen, int[] bs) { super(any,widen,bs); } + public static TypeConAryI make( int[] bs ) { return new TypeConAryI(false,(byte)0,bs).intern(); } + @Override TypeConAryI _make( boolean any, byte widen ) { return new TypeConAryI(any,widen,_ary); } + static final TypeConAryI I123 = make(new int[]{1,2,3}); @Override public long at8(int idx) { return _ary[idx]; } @Override public int len() { return _ary.length; } @Override public int log_size() { return 2; } @Override public String str() { return "[i32]"; } - @Override boolean eq(Type t) { return Arrays.equals(_ary,((TypeConAryI)t)._ary); } + @Override boolean eq(Type t) { return t instanceof TypeConAryI ary && _widen==ary._widen && Arrays.equals(_ary,ary._ary); } @Override int hash() { return Arrays.hashCode(_ary); } } diff --git a/src/main/java/com/seaofnodes/simple/type/TypeFunPtr.java b/src/main/java/com/seaofnodes/simple/type/TypeFunPtr.java index cbf06e0c..50743f69 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeFunPtr.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeFunPtr.java @@ -175,8 +175,13 @@ public class TypeFunPtr extends TypeNil { public Type ret() { return _ret; } public int nargs() { return _sig.length; } public int fidx() { assert Long.bitCount(_fidxs)==1; return Long.numberOfTrailingZeros(_fidxs); } + public int nfcns() { + if( _fidxs < 0 ) return Integer.MAX_VALUE; // Infinite choices + return Long.bitCount(_fidxs); + } + // Used to walk over type structures @Override int nkids() { return _sig.length+1; } @Override Type at( int idx ) { return idx == _sig.length ? _ret : _sig[idx]; @@ -258,7 +263,7 @@ public class TypeFunPtr extends TypeNil { return tilde+fidx; } - // Usage: for( long fidxs=fidxs(); fidxs!=0; fidxs=nextFIDX(fidxs) { int fidxs = Long.numberOfTrailingZeros(fidxs); ... } + // Usage: for( long fidxs=fidxs(); fidxs!=0; fidxs=nextFIDX(fidxs) ) { int fidx = Long.numberOfTrailingZeros(fidxs); ... } public static long nextFIDX(long fidxs) { return fidxs & (fidxs-1); } } diff --git a/src/main/java/com/seaofnodes/simple/type/TypeInteger.java b/src/main/java/com/seaofnodes/simple/type/TypeInteger.java index 1d398e3b..74fbfb9f 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeInteger.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeInteger.java @@ -18,24 +18,45 @@ public class TypeInteger extends Type { */ public long _min, _max; + public byte _widen; + private static final Ary<TypeInteger> FREE = new Ary<>(TypeInteger.class); - private TypeInteger(long min, long max) { super(TINT); init(min,max); } - private TypeInteger init(long min, long max) { _min = min; _max = max; return this; } - public static TypeInteger malloc(long lo, long hi) { return FREE.isEmpty() ? new TypeInteger(lo,hi) : FREE.pop().init(lo,hi); } - public static TypeInteger make(long lo, long hi) { - TypeInteger i = malloc(lo,hi); + private TypeInteger(long min, long max, byte widen) { super(TINT); init(min,max,widen); } + private TypeInteger init(long min, long max, byte widen) { + _min = min; _max = max; _widen=widen; + return this; + } + public static TypeInteger malloc(long lo, long hi, byte widen) { return FREE.isEmpty() ? new TypeInteger(lo,hi,widen) : FREE.pop().init(lo,hi,widen); } + public static TypeInteger make(long lo, long hi) { return make(lo,hi,(byte)0); } + public static TypeInteger make(long lo, long hi, byte widen) { + TypeInteger i = malloc(lo,hi,widen); TypeInteger t2 = i.intern(); return t2==i ? i : t2.free(i); } + public TypeInteger makeWide(byte widen) { + if( widen == _widen ) return this; + if( _min == Long.MIN_VALUE && _max == Long.MAX_VALUE ) + return TypeInteger.BOT; + if( _min==_max ) return this; // Leave constants always narrow + return make(_min,_max,widen); + } @Override TypeInteger free(Type t) { TypeInteger i = (TypeInteger)t; i._min = i._max = 0; + i._widen = 0; i._hash = 0; i._dual = null; FREE.push(i); return this; } + public Type same_but_slightly_wider_than( Type minType ) { + return _widen < 3 ? make(_min,_max, (byte)(_widen+1)) : minType; + } + // Force max widen + @Override public Type widen() { + return _widen==3 ? this : make(_min,_max,(byte)3); + } public static TypeInteger constant(long con) { return make(con, con); } public final static TypeInteger ZERO= make(0,0); @@ -43,20 +64,31 @@ public class TypeInteger extends Type { public final static TypeInteger TRUE= make(1,1); public final static TypeInteger TWO = make(2,2); // Shows up in some Simple tests as the starting argument - public final static TypeInteger I1 = make(-1,0); - public final static TypeInteger I8 = make(-128,127); - public final static TypeInteger I16 = make(-32768,32767); - public final static TypeInteger I32 = make(-1L<<31,(1L<<31)-1); - public final static TypeInteger BOT = make(Long.MIN_VALUE,Long.MAX_VALUE); + public final static TypeInteger I1 = make(-1,0,(byte)3); + public final static TypeInteger I8 = make(-128,127,(byte)3); + public final static TypeInteger I16 = make(-32768,32767,(byte)3); + public final static TypeInteger I32 = make(-1L<<31,(1L<<31)-1,(byte)3); + public final static TypeInteger BOT = make(Long.MIN_VALUE,Long.MAX_VALUE,(byte)3); public final static TypeInteger TOP = (TypeInteger)BOT.dual(); - public final static TypeInteger U1 = make(0,1); + public final static TypeInteger U1 = make(0,1,(byte)3); public final static TypeInteger BOOL= U1; - public final static TypeInteger U8 = make(0,255); - public final static TypeInteger U16 = make(0,65535); - public final static TypeInteger U32 = make(0,(1L<<32)-1); - - public static void gather(ArrayList<Type> ts) { ts.add(I32); ts.add(BOT); ts.add(U1); ts.add(I1); ts.add(U8); } + public final static TypeInteger U8 = make(0,255,(byte)3); + public final static TypeInteger U16 = make(0,65535,(byte)3); + public final static TypeInteger U32 = make(0,(1L<<32)-1,(byte)3); + + public final static TypeInteger FATBOOL = make(0,1,(byte)2); + + public static void gather(ArrayList<Type> ts) { + ts.add(I32); ts.add(BOT); ts.add(U1); ts.add(I1); ts.add(U8); ts.add(ZERO); ts.add(FATBOOL); + // Ranges before and after excluding zero, at each widening level. + for( byte widen=0; widen<=3; widen++ ) { + ts.add(make(0,255,widen)); + ts.add(make(1,255,widen)); + ts.add(make(-255,0,widen)); + ts.add(make(-255,-1,widen)); + } + } @Override public String str() { if( _isConstant() ) return ""+_min; @@ -95,6 +127,7 @@ public class TypeInteger extends Type { else if (-0xFFFFFFFFL <= _min && _min <= 0xFFFFFFFFL) return 2; else return 3; } + if( -128 <= _min && _max < 128 ) return 0; // 1 byte throw Utils.TODO(); } @@ -119,21 +152,18 @@ public class TypeInteger extends Type { @Override public Type xmeet(Type other) { - if( other instanceof TypeConAry ary ) return ary.imeet(this); // Invariant from caller: 'this' != 'other' and same class (TypeInteger) TypeInteger i = (TypeInteger)other; // Contract - return make(Math.min(_min,i._min), Math.max(_max,i._max)); + return make(Math.min(_min,i._min), Math.max(_max,i._max), (byte)Math.max(_widen,i._widen)); } - @Override TypeInteger xdual() { - return _min==_max ? this : malloc(_max,_min); - } + @Override TypeInteger xdual() { return malloc(_max,_min,(byte)(3-_widen)); } @Override public TypeInteger nonZero() { if( isHigh() ) return this; if( this==ZERO ) return null; // No sane answer - if( _min==0 ) return make(1,Math.max(_max,1)); // specifically good on BOOL - if( _max==0 ) return make(_min,-1); + if( _min==0 ) return make(1,Math.max(_max,1),_widen); // specifically good on BOOL + if( _max==0 ) return make(_min,-1,_widen); return this; } @Override public Type makeZero() { return ZERO; } @@ -146,8 +176,8 @@ public class TypeInteger extends Type { return isHigh() ? dual() : this; } - @Override int hash() { return Utils.fold(_min) * Utils.fold(_max); } + @Override int hash() { return Utils.fold(_min) * Utils.fold(_max) + _widen; } @Override public boolean eq( Type t ) { - return t instanceof TypeInteger i && _min==i._min && _max==i._max; + return t instanceof TypeInteger i && _min==i._min && _max==i._max && _widen==i._widen; } } diff --git a/src/main/java/com/seaofnodes/simple/type/TypeMemPtr.java b/src/main/java/com/seaofnodes/simple/type/TypeMemPtr.java index ad744c8f..9fc90544 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeMemPtr.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeMemPtr.java @@ -67,6 +67,7 @@ public class TypeMemPtr extends TypeNil { public TypeMemPtr makeFrom(TypeStruct obj) { return obj==_obj ? this : make(_nil, obj, _one,_ro); } public TypeMemPtr makeNullable() { return makeFrom((byte)3); } @Override TypeMemPtr makeFrom(byte nil) { return nil==_nil ? this : make(nil, _obj, _one,_ro); } + public TypeMemPtr makeHigh() { return make((byte)0,_obj.makeHigh(),false); } private TypeMemPtr access(boolean ro) { _ro=ro; return this; } diff --git a/src/main/java/com/seaofnodes/simple/type/TypeRPC.java b/src/main/java/com/seaofnodes/simple/type/TypeRPC.java index bd5e2923..a1389540 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeRPC.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeRPC.java @@ -1,5 +1,6 @@ package com.seaofnodes.simple.type; +import com.seaofnodes.simple.util.Ary; import com.seaofnodes.simple.util.SB; import com.seaofnodes.simple.util.Utils; import java.util.ArrayList; @@ -13,19 +14,31 @@ public class TypeRPC extends Type { // A set of CallEndNode IDs (or StopNode); commonly just one. // Basically a sparse bit set - final HashSet<Integer> _rpcs; + HashSet<Integer> _rpcs; // If true, invert the meaning of the bits - final boolean _any; + boolean _any; - private TypeRPC(boolean any, HashSet<Integer> rpcs) { - super(TRPC); - _any = any; - _rpcs = rpcs; + private static final Ary<TypeRPC> FREE = new Ary<>(TypeRPC.class); + private TypeRPC init(boolean any, HashSet<Integer> rpcs) { _any=any; _rpcs=rpcs; return this; } + private TypeRPC() { super(TRPC); } + private static TypeRPC malloc(boolean any, HashSet<Integer> rpcs) { + return (FREE.isEmpty() ? new TypeRPC() : FREE.pop()).init(any,rpcs); } private static TypeRPC make(boolean any, HashSet<Integer> rpcs) { - return new TypeRPC(any,rpcs).intern(); + TypeRPC rpc = (FREE.isEmpty() ? new TypeRPC() : FREE.pop()).init(any,rpcs); + TypeRPC t2 = rpc.intern(); + return t2==rpc ? rpc : t2.free(rpc); } + @Override TypeRPC free(Type t) { + TypeRPC rpc = (TypeRPC)t; + rpc._rpcs = null; + rpc._dual = null; + rpc._hash = 0; + FREE.push(rpc); + return this; + } + @Override boolean isFree() { return _rpcs==null; } public static TypeRPC constant(int cend) { HashSet<Integer> rpcs = new HashSet<>(); @@ -82,8 +95,7 @@ public class TypeRPC extends Type { return make(any,rpcs); } - @Override - Type xdual() { return new TypeRPC(!_any,_rpcs); } + @Override Type xdual() { return malloc(!_any,_rpcs); } @Override boolean _isConstant() { return !_any && _rpcs.size()==1; } @Override boolean _isGLB(boolean mem) { return true; } diff --git a/src/main/java/com/seaofnodes/simple/type/TypeStruct.java b/src/main/java/com/seaofnodes/simple/type/TypeStruct.java index f065126a..bb6ce4cb 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeStruct.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeStruct.java @@ -68,6 +68,12 @@ public class TypeStruct extends Type { Field.make("#" ,len , lenAlias,true ,false), Field.make("[]",body,bodyAlias,efinal,false)); } + public TypeStruct makeHigh() { + Field[] fs = new Field[_fields.length]; + for( int i=0; i<_fields.length; i++ ) + fs[i] = _fields[i].makeFrom(Type.TOP); + return make(_name,false,fs); + } public TypeStruct add( Field f ) { assert _open && find(f._fname)==-1; // No double field names diff --git a/src/test/java/com/seaofnodes/simple/BrainFuckTest.java b/src/test/java/com/seaofnodes/simple/BrainFuckTest.java index 9f626805..a3b98fe0 100644 --- a/src/test/java/com/seaofnodes/simple/BrainFuckTest.java +++ b/src/test/java/com/seaofnodes/simple/BrainFuckTest.java @@ -5,8 +5,6 @@ import com.seaofnodes.isa.eval.EvalRisc5; import com.seaofnodes.isa.eval.EvalArm64; import com.seaofnodes.simple.codegen.CodeGen; -import com.seaofnodes.simple.node.cpus.arm.arm; -import com.seaofnodes.simple.node.cpus.riscv.riscv; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -18,21 +16,70 @@ public class BrainFuckTest { @Test public void testBrainFuck() throws IOException { String brain_fuck = "Hello World!\n"; - TestC.run("brain_fuck", brain_fuck, 40); + String src = +""" +// -*- mode: java; -*- +val brain_fuck = { -> + var !program = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."; + int d = 0; + u8[] !output = new u8[0]; + u8[] !data = new u8[100]; - EvalRisc5 R5 = TestRisc5.build("brain_fuck", 0, 28, false); + for( int pc = 0; pc < program#; pc++ ) { + var command = program[pc]; + if (command == 62) { + d++; + } else if (command == 60) { + d--; + } else if (command == 43) { + data[d]++; + } else if (command == 45) { + data[d]--; + } else if (command == 46) { + // Output a byte; increase the output array size + var old = output; + output = new u8[output# + 1]; + for( int i = 0; i < old#; i++ ) + output[i] = old[i]; + output[old#] = data[d]; // Add the extra byte on the end + } else if (command == 44) { + data[d] = 42; + } else if (command == 91) { + if (data[d] == 0) { + for( int d = 1; d > 0; ) { + command = program[++pc]; + if (command == 91) d++; + if (command == 93) d--; + } + } + } else if (command == 93) { + if (data[d]) { + for( int d = 1; d > 0; ) { + command = program[--pc]; + if (command == 93) d++; + if (command == 91) d--; + } + } + } + } + return output; +}; +"""; + TestC.run(src,"brain_fuck", null, brain_fuck, 40); + + EvalRisc5 R5 = TestRisc5.build("brain_fuck", src, 0, 28, false); int trap = R5.step(100000); assertEquals(0,trap); - int ptr = (int)R5.regs[riscv.A0]; + int ptr = (int)R5.regs[com.seaofnodes.simple.node.cpus.riscv.riscv.A0]; assertEquals(brain_fuck.length(),R5.ld4s(ptr)); for( int i=0; i<brain_fuck.length(); i++ ) assertEquals(brain_fuck.charAt(i), R5.ld1z(ptr+4+i)); - EvalArm64 A5 = TestArm64.build("brain_fuck", 0, 28, false); + EvalArm64 A5 = TestArm64.build("brain_fuck", src, 0, 28, false); int trap_arm = A5.step(100000); assertEquals(0,trap_arm); assertEquals(0,trap); - int ptr_arm = (int)A5.regs[arm.X0]; + int ptr_arm = (int)A5.regs[com.seaofnodes.simple.node.cpus.arm.arm.X0]; assertEquals(brain_fuck.length(),A5.ld4s(ptr_arm)); for( int i=0; i<brain_fuck.length(); i++ ) diff --git a/src/test/java/com/seaofnodes/simple/Chapter13Test.java b/src/test/java/com/seaofnodes/simple/Chapter13Test.java index 63f1d12c..62bc1654 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter13Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter13Test.java @@ -8,293 +8,6 @@ import static org.junit.Assert.assertEquals; public class Chapter13Test { - // A placeholder test used to rapidly rotate through fuzzer produced issues - @Test - public void testFuzzer() { - CodeGen code = new CodeGen( -""" -while(---- -arg) { - while(-arg) { - while(-----arg*---0) { - int N=--false==false<--arg; - while(N<-4==N) { - N=N+N; - } - } - { - int kzEl_r7EYz = (3*----0!=-arg) < (37*--97!=0/arg==arg) <= -(--arg!=0); - while(kzEl_r7EYz<---1) { - kzEl_r7EYz=kzEl_r7EYz+kzEl_r7EYz*arg>=24; - if(7) continue; - kzEl_r7EYz=false; - if(-kzEl_r7EYz+arg<-3) continue; - else { - while(kzEl_r7EYz) continue; - arg=----3; - kzEl_r7EYz=-(-----arg*1>-kzEl_r7EYz); - int v2uF_4ba=9; - } - } - } - int pjcp7rv=arg; - { - int m2ya3=--arg-pjcp7rv; - while(m2ya3<-----pjcp7rv>=pjcp7rv+--pjcp7rv!=---pjcp7rv!=-arg<---(-m2ya3)>m2ya3<=-----true>14!=--m2ya3) { - m2ya3=m2ya3+-(--0<=false<pjcp7rv/arg<=-true); - while((--m2ya3)<--arg<-----arg*false!=arg<pjcp7rv*arg) { - pjcp7rv=-3+-arg; - break; - } - while(-3) { - while(67+0-61) m2ya3=m2ya3; - if(----pjcp7rv==---(---arg)) pjcp7rv=0!=-23; - else pjcp7rv=----89; - while(m2ya3!=m2ya3<pjcp7rv) m2ya3=1; - while(--arg<=pjcp7rv) pjcp7rv=-32<=-m2ya3+62; - } - break; - } - } - { - int arg=-1<-9!=(-arg>=-pjcp7rv>=arg<=arg); - while(arg<-arg) { - arg=arg+--arg; - { - while((--93)--pjcp7rv*-pjcp7rv+arg) arg=0-(6>=(--(---41/(0))!=--pjcp7rv)>=---2*33); - pjcp7rv=11; - int c=pjcp7rv; - if(--107) break; - else break; - } - } - } - pjcp7rv=pjcp7rv; - int aR0Wkua=-pjcp7rv==pjcp7rv; - { - if(-0!=-0) while(-true) break; - else { - while(aR0Wkua) pjcp7rv=-0/pjcp7rv; - pjcp7rv=pjcp7rv; - } - } - } - if(-arg) { - { - int Isdlt0fr91=0!=arg; - while(Isdlt0fr91<-Isdlt0fr91==-Isdlt0fr91+true) { - Isdlt0fr91=Isdlt0fr91+-1!=true; - if(-arg) if(--arg<=Isdlt0fr91) Isdlt0fr91=-Isdlt0fr91; - int i=---arg<---arg!=--40; - { - int jVX43Ln4Dm=-(6)==-Isdlt0fr91/----0; - while(jVX43Ln4Dm<--(3-3)) { - jVX43Ln4Dm=jVX43Ln4Dm+-0<25; - i=24<--(jVX43Ln4Dm); - } - } - i=(arg!=----false>=7); - int Te=5>-arg; - break; - } - } - arg=arg!=--true/arg; - { - int UX=arg; - while(UX<-3*arg) { - UX=UX+arg/-1; - arg=-3--(-UX- -47<arg==--arg==arg)/arg- -UX>=-arg; - if(---12) while(-UX) break; - break; - } - } - continue; - } - if(arg) arg=--0; - else if(1) continue; - int DtTlhjYq=19==arg; - { - arg=--DtTlhjYq<=(DtTlhjYq/---DtTlhjYq<=-DtTlhjYq); - if(---arg) continue; - else { - int Zsl=40; - while(Zsl<--Zsl--false>((Zsl))==Zsl!=--DtTlhjYq-DtTlhjYq-DtTlhjYq) { - Zsl=Zsl+arg; - } - } - if((arg)) if(-DtTlhjYq) { - } - else while(((2)==3*arg/DtTlhjYq)<=0==---arg) return false; - else { - int lwbF=arg>=0; - while(lwbF<57) { - lwbF=lwbF+--(-arg+lwbF)>=-2>=arg!=arg; - arg=----0+0; - while(49) break; - if(true) DtTlhjYq=-----arg; - DtTlhjYq=0!=-----(0); - } - } - arg=---arg!=DtTlhjYq/--0; - DtTlhjYq=-DtTlhjYq/(--arg<arg); - if(32) { - int q=-DtTlhjYq; - while(q<arg*(0*q)/0) { - q=q+DtTlhjYq; - DtTlhjYq=arg; - } - } - else if(--arg) if(15) break; - else arg=0==arg<=-55>DtTlhjYq; - else { - } - DtTlhjYq=-0; - { - while((0)<-arg) DtTlhjYq=-DtTlhjYq; - } - if(30/--(arg)>=0) DtTlhjYq=-0>=arg; - else { - int Y2wcIQJ=--DtTlhjYq*---11; - if(arg==arg) { - Y2wcIQJ=-----Y2wcIQJ; - Y2wcIQJ=Y2wcIQJ<7; - if(DtTlhjYq) arg=arg; - else break; - while(-arg!=-31==(false<=-15>=-DtTlhjYq+--6*-----Y2wcIQJ<=---arg!=-Y2wcIQJ<=---0<-arg*--Y2wcIQJ)) DtTlhjYq=arg!=3; - } - continue; - } - arg=DtTlhjYq; - arg=--3/(---arg)>=80>=-DtTlhjYq<=DtTlhjYq; - arg=51+---(-true)!=arg!=----1==-DtTlhjYq; - if(11<=arg) if((arg)+79<32+(-arg)) continue; - else if(true==DtTlhjYq) break; - break; - } -} -if(arg!=62==arg) { - while(---arg) { - { - int bhmDacPM=arg/arg; - while(bhmDacPM<arg) { - bhmDacPM=bhmDacPM+80*((-bhmDacPM)/---bhmDacPM>1)<bhmDacPM-2!=7; - arg=-0; - arg=bhmDacPM>=-arg+-arg; - break; - } - } - int arg=true; - arg=arg<=arg; - { - int KlC=30; - while(KlC<-2) { - KlC=KlC+-1!=25<=-KlC>KlC>----0; - int Ij=arg>=-arg<=---10; - { - int LAbgurVa2R=-arg!=Ij; - while(LAbgurVa2R<-true) { - LAbgurVa2R=LAbgurVa2R+Ij; - KlC=-LAbgurVa2R; - Ij=42*(-Ij>true); - while(Ij) arg=KlC; - KlC=-----7>-(--KlC<--7)==-LAbgurVa2R; - } - } - int a=Ij<=-KlC; - if(Ij) { - int r1W=a!=-false; - } - else { - arg=56>=Ij; - while(54) break; - arg=8>=-(a<--Ij)/a>=-a-KlC; - } - int Yt_T=KlC; - arg=KlC; - } - } - if(----false/--arg/12+-----0) if(-9+-arg) while(arg!=(arg)) arg=--1>=-71-arg!=---(--arg*11+102)/--arg; - else if(----arg) continue; - if(-arg-arg) { - arg=-(-arg)*--(-3)<(-7==-arg----arg); - { - int arg=arg; - while(arg<-0>arg==-arg-(-arg>1+11)) { - arg=arg+6-arg!=--0>---30>=---arg<=arg/(3)+---arg; - } - } - arg=-arg+arg; - arg=--47+-arg<1>arg*(-arg==-arg- -0>3); - arg=(----arg)!=arg+--59; - arg=- -4+arg==-(arg)-arg; - } - else { - while(--true-----true*-25+-18>arg>=-----(-arg)---13) { - arg=-0+--true<false; - continue; - } - arg=true<=arg; - break; - } - arg=arg*22<--(0+-arg); - { - continue; - } - } - arg=1*---((3<=true)==---2); - arg=7+-(-1); - return arg+--true; -} -else { - int o3ypEsewxM=-(---arg); - int vzXB=(-(---11<=--o3ypEsewxM>=--0))<=-0/-arg; - int L=-arg; - int B4mHcrf=---vzXB; - int oZWGdzZl=-o3ypEsewxM; - int K6tQqa1=11; - while(0!=--L) { - int sdZfTM=vzXB*true+K6tQqa1; - while(sdZfTM<false) { - sdZfTM=sdZfTM+arg; - sdZfTM=oZWGdzZl; - K6tQqa1=-K6tQqa1; - arg=---K6tQqa1; - while((3+-K6tQqa1)<oZWGdzZl) { - if(-----(-1)) sdZfTM=-false; - {} - } - K6tQqa1=vzXB!=-(B4mHcrf+-7>false); - sdZfTM=vzXB; - } - } - L=false; - while(31) B4mHcrf=arg; - oZWGdzZl=-0<--oZWGdzZl<=--2; - if(K6tQqa1>=20<=46) { - if(-1+-L) if(oZWGdzZl) { - int wmhv=-----0; - } - int arg=0; - o3ypEsewxM=---(oZWGdzZl); - return -oZWGdzZl/0; - } - else if(arg) { - int yKk5=B4mHcrf>=4>K6tQqa1<-B4mHcrf/o3ypEsewxM; - return -K6tQqa1; - } - else { - if(---0) { - {} - {} - } - return o3ypEsewxM; - } -} -"""); - code.parse().opto().typeCheck().GCM(); - assertEquals("return 9;", code.print()); - } - - @Test public void testPrimes() { CodeGen code = new CodeGen( diff --git a/src/test/java/com/seaofnodes/simple/Chapter18Test.java b/src/test/java/com/seaofnodes/simple/Chapter18Test.java index 902344ed..44c365dd 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter18Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter18Test.java @@ -223,7 +223,7 @@ var fcn = arg ? { int x -> x*x; } : { int x -> x+x; }; return fcn(3); """); code.parse().opto(); - assertEquals("Stop[ return #2; return (Parm_x($fun21,i64,3)*x); return (Parm_x($fun22,i64,3)<<1); ]", code._stop.toString()); + assertEquals("Stop[ return #2; return (Parm_x($fun21,i64)*x); return (Parm_x($fun22,i64)<<1); ]", code._stop.toString()); assertEquals("6", Eval2.eval(code, 0)); assertEquals("9", Eval2.eval(code, 1)); } @@ -233,7 +233,7 @@ return fcn(3); public void testFcn5() { CodeGen code = new CodeGen("val fact = { int x -> x <= 1 ? 1 : x*fact(x-1); }; return fact(arg);"); code.parse().opto().typeCheck(); - assertEquals("Stop[ return #2; return Phi(Region,1,(Parm_x(fact,i64,arg,(x-1))*#2)); ]", code._stop.toString()); + assertEquals("Stop[ return #2; return Phi(Region,1,(Parm_x(fact,i64)*#2)); ]", code._stop.toString()); assertEquals( "1", Eval2.eval(code, 0)); assertEquals( "1", Eval2.eval(code, 1)); assertEquals( "2", Eval2.eval(code, 2)); @@ -249,7 +249,7 @@ struct S { int i; }; val newS = { int x -> return new S { i=x; }; }; return newS(1).i; """); - code.parse().opto().typeCheck().GCM(); + code.parse().opto().typeCheck(); assertEquals("return 1;", code._stop.toString()); assertEquals("1", Eval2.eval(code, 0)); } @@ -264,8 +264,8 @@ val f = {->1;}; val g = {->2;}; return 2; """); - code.parse().opto().typeCheck().GCM(); - assertEquals("Stop[ return 1; return 1; return 2; ]", code._stop.toString()); + code.parse().opto().typeCheck(); + assertEquals("return 1;", code._stop.toString()); assertEquals("1", Eval2.eval(code, 0)); } @@ -399,7 +399,7 @@ for(;;) { val g = { -> g(); }; -return 0; +return g(); """); try { code.parse().opto().typeCheck(); fail(); } catch( Exception e ) { assertEquals("No defined return type",e.getMessage()); } diff --git a/src/test/java/com/seaofnodes/simple/Chapter19Test.java b/src/test/java/com/seaofnodes/simple/Chapter19Test.java index 23b45e46..8a840787 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter19Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter19Test.java @@ -27,7 +27,7 @@ public class Chapter19Test { fun.addDef(code._start); code.link(fun); var otherReturn = tfp.makeFrom(TypeInteger.constant(654321)); - org.junit.Assert.assertSame(fun,code.link(otherReturn)); + org.junit.Assert.assertSame(fun,code._link(otherReturn)); org.junit.Assert.assertTrue(con.toString().contains("printerTarget")); assertEquals("printerTarget",call.name()); } @@ -47,7 +47,38 @@ return 0; @Test public void testString() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/stringHash.smp")); + String src = +""" +struct String { + u8[] !cs; + int _hashCode; +}; + +// Compare two Strings +val equals = { !String !self, !String s -> + if( self == s ) return true; + if( self.cs# != s.cs# ) return false; + for( int i=0; i< self.cs#; i++ ) + if( self.cs[i] != s.cs[i] ) + return false; + return true; +}; + +// Return the String hashCode (cached, and never 0) +val hashCode = { !String self -> + self._hashCode + ? self._hashCode + : (self._hashCode = _hashCodeString(self)); +}; + +val _hashCodeString = { !String self -> + int hash=0; + for( int i=0; i< self.cs#; i++ ) + hash = hash*31 + self.cs[i]; + if( !hash ) hash = 123456789; + return hash; +}; +"""; CodeGen code = new CodeGen(src).parse().opto().typeCheck().GCM().localSched(); assertEquals("Stop[ return Phi(Region,1,0,0,1); return Phi(Region,._hashCode,Phi(Region,123456789,Phi(Loop,0,(.[]+((Phi_hash<<5)-Phi_hash))))); ]", code._stop.toString()); //assertEquals("-4898613127354160978", Eval2.eval(code, 2)); @@ -316,8 +347,20 @@ return A[1]; @Test public void testNewton() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp")) - + "flt farg = arg; return test_sqrt(farg);"; + String src = +""" +val test_sqrt = { flt x -> + flt epsilon = 1e-15; + flt guess = x; + while( 1 ) { + flt next = (x/guess + guess)/2; + if( guess-epsilon <= next & next <= guess+epsilon ) return guess; + //if( guess==next ) return guess; + guess = next; + } +}; +flt farg = arg; return test_sqrt(farg); +"""; CodeGen code = new CodeGen(src).driver(Phase.LocalSched,"x86_64_v2", "SystemV"); assertEquals("return Phi(Loop,(cvtf,arg),(mulf,(addf,(divf,cvtf,Phi_guess),Phi_guess),0.5f));", code.print()); }; @@ -325,7 +368,39 @@ return A[1]; @Test public void sieveOfEratosthenes() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/sieve.smp")); + String src = +""" +val sieve = { int N -> + // The main Sieve array + bool[] !ary = new bool[N]; + // The primes less than N + u32[] !primes = new u32[N>>1]; + // Number of primes so far, searching at index p + int nprimes = 0, p=2; + // Find primes while p^2 < N + while( p*p < N ) { + // skip marked non-primes + while( ary[p] ) p++; + // p is now a prime + primes[nprimes++] = p; + // Mark out the rest non-primes + for( int i = p + p; i < ary#; i+= p ) + ary[i] = true; + p++; + } + + // Now just collect the remaining primes, no more marking + for( ; p < N; p++ ) + if( !ary[p] ) + primes[nprimes++] = p; + + // Copy/shrink the result array + u32[] !rez = new u32[nprimes]; + for( int j=0; j < nprimes; j++ ) + rez[j] = primes[j]; + return rez; +}; +"""; CodeGen code = new CodeGen(src).driver(Phase.LocalSched,"x86_64_v2", "SystemV"); assertEquals("return []u32;", code.print()); //assertEquals("u32[ 2,3,5,7,11,13,17,19]",Eval2.eval(code, 20)); diff --git a/src/test/java/com/seaofnodes/simple/Chapter20Test.java b/src/test/java/com/seaofnodes/simple/Chapter20Test.java index 08a23ef0..4ca1dbda 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter20Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter20Test.java @@ -239,8 +239,8 @@ s.cs[1] = 108; // l hashCode(s); """; testTarget(src,"x86_64_v2", "SystemV",9,null); - testTarget(src,"riscv" , "SystemV",4,null); - testTarget(src,"arm" , "SystemV",1,null); + testTarget(src,"riscv" , "SystemV",3,null); + testTarget(src,"arm" , "SystemV",0,null); } @Test diff --git a/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/src/test/java/com/seaofnodes/simple/Chapter21Test.java index 30d22fc9..5b2c3a54 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter21Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter21Test.java @@ -309,7 +309,7 @@ public class Chapter21Test { } - // Enabled in Chapter 23; measured there by Chapter23AllocTest. + // Frozen Jig runs in Chapter23AllocTest; the revised input is in Chapter24AllocTest. @Test @Ignore public void testJig() throws IOException { String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/jig.smp")); @@ -343,7 +343,17 @@ public class Chapter21Test { @Test public void testArray1() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/array1.smp")); + String src = +""" +int[] !ary = new int[arg]; +// Fill [0,1,2,3,4,...] +for( int i=0; i<ary#; i++ ) + ary[i] = i; +// Fill [0,1,3,6,10,...] +for( int i=0; i<ary#-1; i++ ) + ary[i+1] += ary[i]; +return ary[1] * 1000 + ary[3]; // 1 * 1000 + 6 +"""; testCPU(src,"x86_64_v2", "SystemV",-1,"return .[];"); testCPU(src,"riscv" , "SystemV", 7,"return (add,.[],(mul,.[],1000));"); testCPU(src,"arm" , "SystemV", 5,"return (add,.[],(mul,.[],1000));"); @@ -351,7 +361,19 @@ public class Chapter21Test { @Test public void testAntiDeps1() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/antiDep1.smp")); + String src = +""" +struct S { int f; }; +var v0 = new S; +!S? !v1; +if (arg) v1 = new S; +if (v1) { + v0.f = v1.f; +} else { + v0.f = 2; +} +return v0; +"""; testCPU(src,"x86_64_v2", "SystemV", 7,"return mov(mov(S));"); testCPU(src,"riscv" , "SystemV",10,"return mov(mov(S));"); testCPU(src,"arm" , "SystemV",10,"return mov(mov(S));"); @@ -359,18 +381,92 @@ public class Chapter21Test { @Test public void testString() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/stringHash.smp")); + String src = +""" +struct String { + u8[] !cs; + int _hashCode; +}; + +// Compare two Strings +val equals = { !String !self, !String s -> + if( self == s ) return true; + if( self.cs# != s.cs# ) return false; + for( int i=0; i< self.cs#; i++ ) + if( self.cs[i] != s.cs[i] ) + return false; + return true; +}; + +// Return the String hashCode (cached, and never 0) +val hashCode = { !String self -> + self._hashCode + ? self._hashCode + : (self._hashCode = _hashCodeString(self)); +}; + +val _hashCodeString = { !String self -> + int hash=0; + for( int i=0; i< self.cs#; i++ ) + hash = hash*31 + self.cs[i]; + if( !hash ) hash = 123456789; + return hash; +}; +"""; testCPU(src,"x86_64_v2", "SystemV", 9,null); testCPU(src,"riscv" , "SystemV", 3,null); testCPU(src,"arm" , "SystemV", 1,null); } @Test public void testStringExport() throws IOException { - TestC.run("stringHash", 9); + String src = +""" +struct String { + u8[] !cs; + int _hashCode; +}; + +// Compare two Strings +val equals = { !String !self, !String s -> + if( self == s ) return true; + if( self.cs# != s.cs# ) return false; + for( int i=0; i< self.cs#; i++ ) + if( self.cs[i] != s.cs[i] ) + return false; + return true; +}; + +// Return the String hashCode (cached, and never 0) +val hashCode = { !String self -> + self._hashCode + ? self._hashCode + : (self._hashCode = _hashCodeString(self)); +}; + +val _hashCodeString = { !String self -> + int hash=0; + for( int i=0; i< self.cs#; i++ ) + hash = hash*31 + self.cs[i]; + if( !hash ) hash = 123456789; + return hash; +}; +"""; + TestC.run(src, "stringHash",null, "", 9); } @Test public void testLoop2() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/loop2.smp")); + String src = +""" +int i = 0; +while(true) { + i += 1; + if( i==0 ) continue; + if( i==1 ) continue; + if( i==2 ) break; + continue; +} +return i; +"""; testCPU(src,"x86_64_v2", "Win64" ,0,"return (inc,Phi(Loop,0,inc));"); testCPU(src,"riscv" , "SystemV",0,"return ( Phi(Loop,0,addi) + #1 );"); testCPU(src,"arm" , "SystemV",0,"return (inc,Phi(Loop,0,inc));"); @@ -389,9 +485,22 @@ public class Chapter21Test { 8 2.828427 (4.44089e-16) 9 3.000000 (0) """; - TestC.run("newtonFloat",result,34); + String src = +""" +val test_sqrt = { flt x -> + flt epsilon = 1e-15; + flt guess = x; + while( 1 ) { + flt next = (x/guess + guess)/2; + if( guess-epsilon <= next & next <= guess+epsilon ) return guess; + //if( guess==next ) return guess; + guess = next; + } +}; +"""; + TestC.run(src, "newtonFloat", null, result, 34); - EvalRisc5 R5 = TestRisc5.build("newtonFloat", 0, 10, false); + EvalRisc5 R5 = TestRisc5.build("newtonFloat",src, 0, 10, false); R5.fregs[riscv.FA0 - riscv.F_OFFSET] = 3.0; int trap_r5 = R5.step(1000); assertEquals(0,trap_r5); @@ -399,7 +508,7 @@ public class Chapter21Test { assertEquals(1.732051,R5.fregs[riscv.FA0 - riscv.F_OFFSET], 0.00001); // arm - EvalArm64 A5 = TestArm64.build("newtonFloat", 0, 10, false); + EvalArm64 A5 = TestArm64.build("newtonFloat", src,0, 10, false); A5.fregs[arm.D0 - arm.D_OFFSET] = 3.0; int trap_arm = A5.step(1000); assertEquals(0,trap_arm); @@ -408,6 +517,39 @@ public class Chapter21Test { @Test public void testSieve() throws IOException { + String src = +""" +val sieve = { int N -> + // The main Sieve array + bool[] !ary = new bool[N]; + // The primes less than N + u32[] !primes = new u32[N>>1]; + // Number of primes so far, searching at index p + int nprimes = 0, p=2; + // Find primes while p^2 < N + while( p*p < N ) { + // skip marked non-primes + while( ary[p] ) p++; + // p is now a prime + primes[nprimes++] = p; + // Mark out the rest non-primes + for( int i = p + p; i < ary#; i+= p ) + ary[i] = true; + p++; + } + + // Now just collect the remaining primes, no more marking + for( ; p < N; p++ ) + if( !ary[p] ) + primes[nprimes++] = p; + + // Copy/shrink the result array + u32[] !rez = new u32[nprimes]; + for( int j=0; j < nprimes; j++ ) + rez[j] = primes[j]; + return rez; +}; +"""; // The primes int[] primes = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, }; SB sb = new SB().p(primes.length).p("["); @@ -416,11 +558,11 @@ public class Chapter21Test { String sprimes = sb.p("]").toString(); // Compile, link against native C; expect the above string of primes to be printed out by C - TestC.run("sieve",sprimes, 186); + TestC.run(src, "sieve", null, sprimes, 186); // Evaluate on RISC5 emulator; expect return of an array of primes in // the simulated heap. - EvalRisc5 R5 = TestRisc5.build("sieve", 100, 92, false); + EvalRisc5 R5 = TestRisc5.build("sieve", src, 100, 92, false); int trap = R5.step(10000); assertEquals(0,trap); // Return register A0 holds sieve(100) @@ -432,7 +574,7 @@ public class Chapter21Test { // Evaluate on ARM5 emulator; expect return of an array of primes in // the simulated heap. - EvalArm64 A5 = TestArm64.build("sieve", 100, 94, false); + EvalArm64 A5 = TestArm64.build("sieve", src, 100, 94, false); int trap_arm = A5.step(10000); assertEquals(0, trap_arm); int ary_arm = (int)A5.regs[arm.X0]; @@ -443,17 +585,30 @@ public class Chapter21Test { } @Test public void testFibExport() throws IOException { + String src = +""" +val fib = {int n -> + int f1=1; + int f2=1; + while( n-- > 1 ){ + int temp = f1+f2; + f1=f2; + f2=temp; + } + return f2; +}; +"""; String fib = "[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]"; - TestC.run("fib", fib, 24); + TestC.run(src, "fib", null, fib, 24); - EvalRisc5 R5 = TestRisc5.build("fib", 9, 17, false); + EvalRisc5 R5 = TestRisc5.build("fib", src, 9, 17, false); int trap = R5.step(100); assertEquals(0,trap); // Return register A0 holds fib(8)==55 assertEquals(55,R5.regs[riscv.A0]); // arm - EvalArm64 A5 = TestArm64.build("fib", 9, 17, false); + EvalArm64 A5 = TestArm64.build("fib", src, 9, 17, false); int trap_arm = A5.step(100); assertEquals(0,trap_arm); // Return register X0 holds fib(8)==55 diff --git a/src/test/java/com/seaofnodes/simple/Chapter22Test.java b/src/test/java/com/seaofnodes/simple/Chapter22Test.java index ea210e3f..c77221bf 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter22Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter22Test.java @@ -186,7 +186,8 @@ public class Chapter22Test { testCPU(src,"arm","SystemV",0,"return Top;"); } - // Enabled in Chapter 23; measured there by Chapter23AllocTest. + + // Frozen Jig runs in Chapter23AllocTest; the revised input is in Chapter24AllocTest. @Test @Ignore public void testJig() throws IOException { String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/jig.smp")); @@ -223,11 +224,11 @@ return 0; assertEquals(56, testCPUSize(src, "arm","SystemV",4,"return 0;")); // do assertEquals here - EvalRisc5 R5 = TestRisc5.build("sext_str_not_fold_away", 0, 4, false); + EvalRisc5 R5 = TestRisc5.build("sext_str_not_fold_away", src,0, 4, false); int trap = R5.step(100); assertEquals(0,trap); - EvalArm64 A5 = TestArm64.build("sext_str_not_fold_away", 0, 4, false); + EvalArm64 A5 = TestArm64.build("sext_str_not_fold_away", src, 0, 4, false); trap = A5.step(100); assertEquals(0,trap); @@ -243,11 +244,11 @@ return 0; return 0; """; - EvalRisc5 R5 = TestRisc5.build("sext_str_not_fold_away_2", 0, 4, false); + EvalRisc5 R5 = TestRisc5.build("sext_str_not_fold_away_2", src, 0, 4, false); int trap = R5.step(100); assertEquals(0,trap); - EvalArm64 A5 = TestArm64.build("sext_str_not_fold_away_2", 0, 4, false); + EvalArm64 A5 = TestArm64.build("sext_str_not_fold_away_2", src, 0, 4, false); int trap_arm = A5.step(100); assertEquals(0,trap_arm); @@ -267,11 +268,11 @@ p.age = (arg<<48)>>48; return 0; """; - EvalRisc5 R5 = TestRisc5.build("sext_str_fold_away", 0, 5, false); + EvalRisc5 R5 = TestRisc5.build("sext_str_fold_away", src, 0, 5, false); int trap = R5.step(100); assertEquals(0,trap); - EvalArm64 A5 = TestArm64.build("sext_str_fold_away", 0, 5, false); + EvalArm64 A5 = TestArm64.build("sext_str_fold_away", src, 0, 5, false); int trap_arm = A5.step(100); assertEquals(0,trap_arm); @@ -284,8 +285,19 @@ return 0; // Int now is changed to 4 bytes. @Test public void testPerson() throws IOException { + String src = +""" +struct Person { + i32 age; +}; + +val fcn = { !Person?[] !ps, int x -> + if( ps[x] ) + ps[x].age++; +}; +"""; String person = "6\n"; - TestC.run("person", person, 0); + TestC.run(src, "person", null, person, 0); // Memory layout starting at PS: int ps = 1<<16; // Person array pointer starts at heap start @@ -296,7 +308,7 @@ return 0; int p1 = ps+4*8+1*8; // P2 = { age } // sizeof=8 int p2 = ps+4*8+2*8; - EvalRisc5 R5 = TestRisc5.build("person", ps, 0, false); + EvalRisc5 R5 = TestRisc5.build("person", src, ps, 0, false); R5.regs[riscv.A1] = 1; // Index 1 R5.st8(ps,3); // Length R5.st8(ps+1*8,p0); @@ -312,7 +324,7 @@ return 0; assertEquals(17+1,R5.ld8(p1)); assertEquals(60+0,R5.ld8(p2)); - EvalArm64 A5 = TestArm64.build("person", ps, 0, false); + EvalArm64 A5 = TestArm64.build("person", src, ps, 0, false); A5.regs[arm.X1] = 1; // Index 1 A5.st8(ps, 3); A5.st8(ps+1*8,p0); @@ -351,18 +363,22 @@ return cc.cz; @Test public void testHelloWorld() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/helloWorld.smp")); + String src = +""" +sys.io.p("Hello, World!"); +return 0; +"""; TestC.run(src,TestC.CALL_CONVENTION,null, null,null,"build/objs/helloWorld","","Hello, World!",0); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("helloWorld", 0, 2, false); + EvalRisc5 R5 = TestRisc5.build("helloWorld", src, 0, 2, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); assertEquals("Hello, World!",R5._stdout.toString()); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("helloWorld", 0, 2, false); + EvalArm64 arm = TestArm64.build("helloWorld", src,0, 2, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); @@ -392,17 +408,21 @@ return sum(is); @Test @Ignore public void testEcho() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/echo.smp")); + String src = +""" +// Echo stdin to stdout. +return sys.io.p( sys.io.stdin() ); +"""; TestC.run(src,TestC.CALL_CONVENTION,null, null,null,"build/objs/echo","","",0); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("echo", 0, 2, false); + EvalRisc5 R5 = TestRisc5.build("echo", src, 0, 2, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("echo", 0, 2, false); + EvalArm64 arm = TestArm64.build("echo", src, 0, 2, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); diff --git a/src/test/java/com/seaofnodes/simple/Chapter23Test.java b/src/test/java/com/seaofnodes/simple/Chapter23Test.java index 0feaa5de..884e77e5 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter23Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter23Test.java @@ -25,6 +25,8 @@ public class Chapter23Test { @Test public void testDiagnosticTypeAccessors() throws Exception { new CodeGen("return 0;").parse(); var tfp = TypeFunPtr.TEST; + var con = new ConstantNode(tfp); + var call = new CallNode(null,con,con,con); var field = Type.class.getDeclaredField("VISIT"); field.setAccessible(true); var visit = (java.util.Map<Object,Type>)field.get(null); @@ -34,6 +36,9 @@ public class Chapter23Test { assertEquals(0,TypeInteger.ZERO.alignment()); assertEquals(0,TypeInteger.ZERO.value()); org.junit.Assert.assertTrue(tfp._isConstant()); + con.toString(); + call.name(); + con.p(1); org.junit.Assert.assertSame(Type.BOTTOM,visit.get(marker)); assertEquals(1,visit.size()); } finally { visit.clear(); } @@ -94,10 +99,6 @@ var apply = { i64 x, { i64 -> u32 } fcn -> """; } - @Test @Ignore - public void myOwnSake2() throws IOException { - TestC.runS("print","Or",0); - } static CodeGen testCPU( String src, String cpu, String os, int spills, String stop ) { CodeGen code = new CheckedCodeGen(src).driver(CodeGen.Phase.Encoding,cpu,os); @@ -110,17 +111,32 @@ var apply = { i64 x, { i64 -> u32 } fcn -> @Test public void testOr() throws IOException { - TestC.runS("or1","Or",0); + String src = + """ + int a = 1; + int b = 0; + + if(a++ || b++ ) { + if(b == 0 && a == 2) { + sys.io.p("Or"); + } + } else{ + sys.io.p("And"); + } + return 0; + """; + + TestC.runSF("or1", src, null, "Or", 0); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("or1", 0, 2, false); + EvalRisc5 R5 = TestRisc5.build("or1", src, 0, 2, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); assertEquals("Or",R5._stdout.toString()); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("or1", 0, 2, false); + EvalArm64 arm = TestArm64.build("or1", src,0, 2, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); @@ -129,17 +145,29 @@ var apply = { i64 x, { i64 -> u32 } fcn -> @Test public void testAnd() throws IOException { - TestC.runS("and1","And",0); + String src = + """ + int a = 1; + int b = 1; + + if(a && b) { + sys.io.p("And"); + } else { + sys.io.p("Or"); + } + return 0; + """; + TestC.runSF("and1", src, null, "And", 0); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("and1", 0, 2, false); + EvalRisc5 R5 = TestRisc5.build("and1", src, 0, 2, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); assertEquals("And",R5._stdout.toString()); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("and1", 0, 2, false); + EvalArm64 arm = TestArm64.build("and1", src, 0, 2, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); @@ -148,24 +176,38 @@ var apply = { i64 x, { i64 -> u32 } fcn -> @Test public void testAndPtr() throws IOException { + // Todo: have one src here String src = -""" -struct S { !S? !fld; }; -val ptr = arg == 1 ? null : new S{fld = arg==1 ? null : new S{fld = null;};}; -return ptr && ptr.fld ? "true" : "false"; - """; + """ + struct S { !S? !fld; }; + val ptr = arg == 1 ? null : new S{fld = arg==1 ? null : new S{fld = null;};}; + return ptr && ptr.fld ? "true" : "false"; + """; + String src2 = + """ + struct S { !S? !fld; }; + + val ptr = arg == 1 ? null : new S{fld = arg==1 ? null : new S{fld = null;};}; + if( ptr && ptr.fld ) { + sys.io.p("true"); + } else { + sys.io.p("false"); + } + + return 0; + """; CodeGen code = new CodeGen(src).parse().opto().typeCheck(); assertEquals("[97-117][ 116,114,117,101]", Eval2.eval(code, 0)); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("ptrand", 1, 8, false); + EvalRisc5 R5 = TestRisc5.build("ptrand",src2, 1, 8, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); assertEquals("false",R5._stdout.toString()); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("ptrand", 1, 8, false); + EvalArm64 arm = TestArm64.build("ptrand", src2, 1, 8, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); @@ -175,37 +217,80 @@ return ptr && ptr.fld ? "true" : "false"; // conditional side effect @Test public void testCondSideEffAnd() throws IOException { - TestC.runS("and2","Effected",0); + String src = + """ + int a = 1; + int b = 1; + + int x=1; + int y=1; + int z=0; + + int g = x++ && y++ && z++; + + if(x == 2 && y == 2 && z == 1 && g == 0) { + sys.io.p("Effected"); + } else { + sys.io.p("Not effected"); + } + return 0; + """; + + TestC.runSF("and2", src, null, "Effected", 0); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("and2", 0, 2, false); + EvalRisc5 R5 = TestRisc5.build("and2", src, 0, 2, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); assertEquals("Effected",R5._stdout.toString()); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("and2", 0, 2, false); + EvalArm64 arm = TestArm64.build("and2", src, 0, 2, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); assertEquals("Effected",arm._stdout.toString()); } - @Test public void testCondSideEffOr() throws IOException { - TestC.runS("or2","Effected",0); + String src = + """ + int a = 1; + int b = 1; + + int x = -1; + int y=1; + int z= -1; + + int g = x++ || y++ || z++; + + int switch = 0; + if(x == 4 || y == 4 || z == 4) { + switch = -1; + } else { + switch = 1; + } + int cd = 1; + if((x == 0 && y == 1 && z==-1) && switch && g) { + sys.io.p("Effected"); + } else { + sys.io.p("Not effected"); + } + return 0; + """; + TestC.runSF("or2", src, null, "Effected", 0); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("or2", 0, 2, false); + EvalRisc5 R5 = TestRisc5.build("or2", src, 0, 2, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); assertEquals("Effected",R5._stdout.toString()); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("or2", 0, 2, false); + EvalArm64 arm = TestArm64.build("or2", src, 0, 2, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); @@ -215,23 +300,41 @@ return ptr && ptr.fld ? "true" : "false"; // test it with function calls @Test public void testFuncCall() throws IOException { - TestC.runS("and3","Or",0); + String src = + """ + // -*- mode: java; -*- + int a = 1; + int b = 1; + + var sq = { int x -> + x*x; + }; + + if(a && sq(0)) { + sys.io.p("And"); + } else { + sys.io.p("Or"); + } + return 0; + """; + TestC.runSF("and3", src, null, "Or", 0); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("and3", 0, 2, false); + EvalRisc5 R5 = TestRisc5.build("and3", src, 0, 2, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); assertEquals("Or",R5._stdout.toString()); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("and3", 0, 2, false); + EvalArm64 arm = TestArm64.build("and3", src, 0, 2, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); assertEquals("Or",arm._stdout.toString()); } + @Test public void testFRefFields() { String src = diff --git a/src/test/java/com/seaofnodes/simple/Chapter24AllocTest.java b/src/test/java/com/seaofnodes/simple/Chapter24AllocTest.java new file mode 100644 index 00000000..7fae2c27 --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/Chapter24AllocTest.java @@ -0,0 +1,170 @@ +package com.seaofnodes.simple; + +import com.seaofnodes.isa.eval.EvalRisc5; + +import com.seaofnodes.isa.eval.EvalArm64; + +import java.io.IOException; +import java.nio.file.*; +import com.seaofnodes.simple.node.cpus.arm.arm; +import com.seaofnodes.simple.node.cpus.riscv.riscv; +import org.junit.Ignore; +import org.junit.Test; +import static org.junit.Assert.*; + +// Revised inherited programs belong to the chapter which changed their inputs. +public class Chapter24AllocTest { + @Test + public void testNewtonInteger() { + String src = +""" +// Newtons approximation to the square root +val sqrt = { int x -> + int guess = x; + while( 1 ) { + int next = (x/guess + guess)/2; + if( next == guess ) return guess; + guess = next; + } +}; +int cast_int = arg+2; +return sqrt(arg) + sqrt(cast_int); +"""; + Chapter24Test.testCPU(src,"x86_64_v2", "Win64" ,40,null); + Chapter24Test.testCPU(src,"riscv" , "SystemV",19,null); + Chapter24Test.testCPU(src,"arm" , "SystemV",19,null); + } + + @Ignore + @Test + public void testJig21() throws IOException { + String src = +""" +struct s0 { + bool v1; + i16 v2; + int v3; + i8 v4; + byte v5; +}; +while(new s0.v3) + while(new s0.v5<<new s0.v4) {} +if(0) { + if(0) { + flt !P5ZUD4=new s0.v2; + } + while(0) {} +} +return new s0.v1; +"""; + Chapter24Test.testCPU(src,"x86_64_v2", "Win64" ,-1,null); + Chapter24Test.testCPU(src,"riscv" , "SystemV",-1,null); + Chapter24Test.testCPU(src,"arm" , "SystemV",-1,null); + } + + @Test public void testStackArguments() throws IOException { + // Test passes more args than registers in Sys5, which is far far more + // than what Win64 allows - so Win64 gets a lot more spills here. + String src = +""" +val addAll = { int i0, flt f1, int i2, flt f3, int i4, flt f5, int i6, flt f7, int x8, flt f9, int i10, flt f11, int i12, flt f13, int i14, flt f15, int x16, flt f17 int x18, flt f19 -> + return + i0 + f1+ i2+ f3+ i4+ f5+ i6+ f7+ x8 +f9 + + i10+f11+i12+f13+i14+f15+x16+f17+x18+f19 ; +}; +"""; + String arg_count = "191.000000\n"; + + TestC.run(src, "arg_count", null, arg_count, TestC.CALL_CONVENTION.equals("Win64") ? 32 : 9); + + EvalRisc5 R5 = TestRisc5.build("no_stack_arg_count", src, 0, 4, false); + + // Todo: handle stack(imaginary stack in emulator) + // pass in float arguments + R5.fregs[riscv.FA0 - riscv.F_OFFSET] = 1.1; + R5.fregs[riscv.FA1 - riscv.F_OFFSET] = 1.1; + R5.fregs[riscv.FA2 - riscv.F_OFFSET] = 1.1; + R5.fregs[riscv.FA3 - riscv.F_OFFSET] = 1.1; + R5.fregs[riscv.FA4 - riscv.F_OFFSET] = 1.1; + R5.fregs[riscv.FA5 - riscv.F_OFFSET] = 1.1; + R5.fregs[riscv.FA6 - riscv.F_OFFSET] = 1.1; + R5.fregs[riscv.FA7 - riscv.F_OFFSET] = 1.1; + + // a0 is passed in arg + R5.regs[riscv.A1] = 2; + R5.regs[riscv.A2] = 2; + R5.regs[riscv.A3] = 2; + R5.regs[riscv.A4] = 2; + R5.regs[riscv.A5] = 2; + R5.regs[riscv.A6] = 2; + R5.regs[riscv.A7] = 2; + + int trap = R5.step(100); + assertEquals(0,trap); + + double result = R5.fregs[riscv.FA0 - riscv.F_OFFSET]; + + assertEquals(22.8, result, 0.00001); + + // arm + EvalArm64 A5 = TestArm64.build("no_stack_arg_count", src, 0, 4, false); + + A5.fregs[arm.D0 - arm.D_OFFSET] = 1.1; + A5.fregs[arm.D1 - arm.D_OFFSET] = 1.1; + A5.fregs[arm.D2 - arm.D_OFFSET] = 1.1; + A5.fregs[arm.D3 - arm.D_OFFSET] = 1.1; + A5.fregs[arm.D4 - arm.D_OFFSET] = 1.1; + A5.fregs[arm.D5 - arm.D_OFFSET] = 1.1; + A5.fregs[arm.D6 - arm.D_OFFSET] = 1.1; + A5.fregs[arm.D7 - arm.D_OFFSET] = 1.1; + + A5.regs[arm.X1] = 2; + A5.regs[arm.X2] = 2; + A5.regs[arm.X3] = 2; + A5.regs[arm.X4] = 2; + A5.regs[arm.X5] = 2; + A5.regs[arm.X6] = 2; + A5.regs[arm.X7] = 2; + + int trap_arm = A5.step(100); + assertEquals(0,trap_arm); + + double result1 = A5.fregs[arm.D0 - arm.D_OFFSET]; + assertEquals(22.8, result1, 0.00001); + } + + @Ignore + @Test + public void testJig22() throws IOException { + String src = +""" +val fib = {int n -> + int temp=0; + int f1=1; + int f2=1; + int i=n; + while( i>1 ){ + temp = f1+f2; + f1=f2; + f2=temp; + i=i-1; + } + return f2; +}; + +fib(10); +"""; + Chapter24Test.testCPU(src,"x86_64_v2", "Win64" ,-1,null); + Chapter24Test.testCPU(src,"riscv" , "SystemV",-1,null); + Chapter24Test.testCPU(src,"arm" , "SystemV",-1,null); + } + + @Test + public void testBubbleSort() throws IOException { + //String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/jig.smp")); + String src = Files.readString(Path.of("docs/examples/BubbleSort.smp")); + Chapter24Test.testCPU(src,"x86_64_v2", "Win64" ,-1,null); + Chapter24Test.testCPU(src,"riscv" , "SystemV",-1,null); + Chapter24Test.testCPU(src,"arm" , "SystemV",-1,null); + } +} diff --git a/src/test/java/com/seaofnodes/simple/Chapter24Test.java b/src/test/java/com/seaofnodes/simple/Chapter24Test.java new file mode 100644 index 00000000..9a657855 --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/Chapter24Test.java @@ -0,0 +1,721 @@ +package com.seaofnodes.simple; + +import com.seaofnodes.isa.eval.EvalRisc5; + +import com.seaofnodes.isa.eval.EvalArm64; + +import com.seaofnodes.simple.codegen.RegAllocTestSupport.CheckedCodeGen; +import com.seaofnodes.simple.node.*; +import com.seaofnodes.simple.type.*; + + +import com.seaofnodes.simple.codegen.CodeGen; +import com.seaofnodes.simple.node.cpus.riscv.riscv; +import java.io.IOException; +import org.junit.Ignore; +import org.junit.Test; +import static org.junit.Assert.*; + +public class Chapter24Test { + @Test public void testColdLoopSelfConflict() { com.seaofnodes.simple.codegen.RegAllocTestSupport.coldLoopSelfConflict(); } + + @Test public void testPrintingDeadFunction() throws Exception { + var code = new CodeGen("return 0;").parse(); + var tfp = TypeFunPtr.TEST; + var fun = new FunNode(null,tfp,"deadPrinterTarget"); + org.junit.Assert.assertTrue(fun.isDead()); + code.link(fun); + var con = new ConstantNode(tfp); + var call = new CallNode(null,con,con,con); + con.toString(); + call.name(); + + org.junit.Assert.assertSame(fun,code._link(tfp)); + // Optimizer lookup still performs its usual lazy cleanup. + org.junit.Assert.assertNull(code.link(tfp)); + org.junit.Assert.assertNull(code._link(tfp)); + } + + + @Ignore + @Test + public void testJig() throws IOException { + String src = "int v0=0; v0 = arg && 0== 0 !=0;"; + testCPU(src,"x86_64_v2", "Win64" ,-1,null); + testCPU(src,"riscv" , "SystemV",-1,null); + testCPU(src,"arm" , "SystemV",-1,null); + } + + static CodeGen testCPU( String src, String cpu, String os, int spills, String stop ) { + CodeGen code = new CheckedCodeGen(src).driver(CodeGen.Phase.Encoding,cpu,os); + SpillStats.record(code,"Chapter24",cpu,os); + SpillStats.checkSpills(spills,code._regAlloc._spillScaled); + if( stop != null ) + assertEquals(stop, code._stop.toString()); + return code; + } + + @Test + public void testOr() throws IOException { + String src = +""" +int a = 1; +int b = 0; + +if(a++ || b++ ) { + if(b == 0 && a == 2) { + sys.io.p("Or"); + } +} else{ + sys.io.p("And"); +} +return 0; +"""; + + TestC.runSF("or1", src, null, "Or", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("or1", src, 0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("Or",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("or1", src,0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("Or",arm._stdout.toString()); + } + + @Test + public void testAnd() throws IOException { + String src = +""" +int a = 1; +int b = 1; + +if(a && b) { + sys.io.p("And"); +} else { + sys.io.p("Or"); +} +return 0; +"""; + TestC.runSF("and1", src, null, "And", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("and1", src, 0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("And",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("and1", src, 0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("And",arm._stdout.toString()); + } + + @Test + public void testAndPtr() throws IOException { + // Todo: have one src here + String src = +""" +struct S { !S? !fld; }; +val ptr = arg == 1 ? null : new S{fld = arg==1 ? null : new S{fld = null;};}; +return ptr && ptr.fld ? "true" : "false"; +"""; + String src2 = +""" +struct S { !S? !fld; }; + +val ptr = arg == 1 ? null : new S{fld = arg==1 ? null : new S{fld = null;};}; +if( ptr && ptr.fld ) { + sys.io.p("true"); +} else { + sys.io.p("false"); +} + +return 0; +"""; + CodeGen code = new CodeGen(src).parse().opto().typeCheck(); + assertEquals("[97-117][ 116,114,117,101]", Eval2.eval(code, 0)); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("ptrand",src2, 1, 8, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("false",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("ptrand", src2, 1, 8, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("false",arm._stdout.toString()); + } + + // conditional side effect + @Test + public void testCondSideEffAnd() throws IOException { + String src = +""" +int a = 1; +int b = 1; + +int x=1; +int y=1; +int z=0; + +int g = x++ && y++ && z++; + +if(x == 2 && y == 2 && z == 1 && g == 0) { + sys.io.p("Effected"); +} else { + sys.io.p("Not effected"); +} +return 0; +"""; + + TestC.runSF("and2", src, null, "Effected", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("and2", src, 0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("Effected",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("and2", src, 0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("Effected",arm._stdout.toString()); + } + + + @Test + public void testCondSideEffOr() throws IOException { + String src = +""" +int a = 1; +int b = 1; + +int x = -1; +int y=1; +int z= -1; + +int g = x++ || y++ || z++; + +int switch = 0; +if(x == 4 || y == 4 || z == 4) { + switch = -1; +} else { + switch = 1; +} +int cd = 1; +if((x == 0 && y == 1 && z==-1) && switch && g) { + sys.io.p("Effected"); +} else { + sys.io.p("Not effected"); +} +return 0; +"""; + TestC.runSF("or2", src, null, "Effected", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("or2", src, 0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("Effected",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("or2", src, 0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("Effected",arm._stdout.toString()); + } + + // test it with function calls + @Test + public void testFuncCall() throws IOException { + String src = +""" +// -*- mode: java; -*- +int a = 1; +int b = 1; + +var sq = { int x -> + x*x; +}; + +if(a && sq(0)) { + sys.io.p("And"); +} else { + sys.io.p("Or"); +} +return 0; +"""; + TestC.runSF("and3", src, null, "Or", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("and3", src, 0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("Or",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("and3", src, 0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("Or",arm._stdout.toString()); + } + + // test it with function calls + @Test + public void testStack1() throws IOException { + String src = +""" +int something_specific = 11; + +if (10 < something_specific < 20) { + sys.io.p("In Range"); +} else { + sys.io.p("Out of Range"); +} +return 0; +"""; + + TestC.runSF("stacked_r_1", src, null, "In Range", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_1", src, 0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("In Range",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_1", src, 0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("In Range",arm._stdout.toString()); + } + + @Test + public void testStack2() throws IOException { + String src = +""" +int score = 75; + +if (60 <= score < 90) { + sys.io.p("In Range"); +} else { +sys.io.p("Out of range"); +} +return 0; +"""; + + TestC.runSF("stacked_r_2", src, null, "In Range", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_2", src, 0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("In Range",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_2", src, 0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("In Range",arm._stdout.toString()); + } + + @Test + public void testStack3() throws IOException { + String src = +""" +var sq = { int x -> + x*x; +}; + +int score = 5; + +val str = (sq(2) <= score < sq(3)) ? "In Range" : "Out of range"; +sys.io.p(str); +return 0; +"""; + + TestC.runSF("stacked_r_3", src, null, "In Range", 5); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_3", src, 0, 5, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("In Range",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_3", src, 0, 5, false); + int trap_1 = arm.step(100); + assertEquals(0,trap_1); + assertEquals(0,arm.regs[0]); + assertEquals("In Range",arm._stdout.toString()); + } + + @Test + public void testStack4() throws IOException { + String src = +""" +int something_specific = 9; + +if (10 < something_specific < 20) { + sys.io.p("In Range"); +} else { + sys.io.p("Out of Range"); +} +return 0; +"""; + + TestC.runSF("stacked_r_4", src, null, "Out of Range", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_4", src,0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("Out of Range",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_4", src, 0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("Out of Range",arm._stdout.toString()); + } + + @Test + public void testStack5() throws IOException { + String src = +""" +var sq = { int x -> + x*x; +}; + +int score = 5; + +if (sq(2) <= score < sq(3)) { +sys.io.p("In Range"); +} else { +sys.io.p("Out of range"); +} + +return 0; +"""; + TestC.runSF("stacked_r_5", src, null, "In Range", 5); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_5", src, 0, 7, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("In Range",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_5", src, 0, 7, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("In Range",arm._stdout.toString()); + } + + + @Test + public void testStack6() { + try { new CodeGen( + """ + return 0 < arg > 1; + """ + ).parse(); fail(); } + catch( RuntimeException e ) { assertEquals("Mixing relational directions in a chained relational test",e.getMessage()); } + } + + @Test + public void testStack9() throws IOException { + String stack9 = "1"; + String src = +""" +var stack9 = { int x -> + (x < 1) == 1; +}; +"""; + String src2 = +""" +return (0 < 1) == 1; +"""; + TestC.run(src, "stacked_r_9x", null, stack9,0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_9", src2, 0, 0, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(1,R5.regs[riscv.A0]); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_9", src2, 0, 0, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(1,arm.regs[0]); + } + + @Test + public void testStack10() throws IOException { + String stack10 = "1"; + String src = +""" +var stack10 = { int x -> + (x < 1) == (1>x); +}; +"""; + String src2 = +""" +return (0 < 1) == (1>0); +"""; + TestC.run(src, "stacked_r_10x", null, stack10,0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_10", src2, 0, 0, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(1,R5.regs[riscv.A0]); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_10", src2,0, 0, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(1,arm.regs[0]); + } + + @Test + public void testStack11() throws IOException { + String stack11 = "1"; + String src = +""" +var stack11 = { int x -> + 0 < x < x+1 < 4; +}; +"""; + String src2 = +""" +return 0 < arg < arg+1 < 4; +"""; + TestC.run(src, "stacked_r_11x", null, stack11,2); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_11", src2, 1, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(1,R5.regs[riscv.A0]); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_11", src2, 1, 0, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(1,arm.regs[0]); + } + + // shows that it is parsed as + // ((0 != x) != 2) + @Test + public void testStack12() throws IOException { + String stack11 = "1"; + String src = + """ + var stack12 = { int x -> + 0 != x != 2; + }; + """; + String src2 = + """ + return 0 != arg != 2; + """; + TestC.run(src, "stacked_r_12x", null, stack11,0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_12", src2, 1, 0, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(1,R5.regs[riscv.A0]); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_12", src2, 1, 0, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(1,arm.regs[0]); + } + + + // shows that it is parsed as + // ((0 == x) == 1) + @Test + public void testStack13() throws IOException { + String stack12 = "1"; + String src = + """ + var stack13 = { int x -> + 0 == x == 1; + }; + """; + String src2 = + """ + return 0 == arg == 1; + """; + TestC.run(src, "stacked_r_13x", null, stack12,0); + + // Compile once per target, then check false, true and negative inputs. + EvalRisc5 R5 = TestRisc5.build("stacked_r_13", src2, 1, 0, false); + for( int arg : new int[]{-1,0,1} ) { + R5._pc = 0; + R5.regs[riscv.A0] = arg; + assertEquals(0,R5.step(100)); + assertEquals(arg==0 ? 1 : 0,R5.regs[riscv.A0]); + } + EvalArm64 arm = TestArm64.build("stacked_r_13", src2, 1, 0, false); + for( int arg : new int[]{-1,0,1} ) { + arm._pc = 0; + arm.regs[0] = arg; + assertEquals(0,arm.step(100)); + assertEquals(arg==0 ? 1 : 0,arm.regs[0]); + } + } + + @Test + public void testFRefFields() { + String src = +""" +// A hypothetical scanner class +struct Scan { + int !x; + u8[~] !buf; + // Skip whitespace + val skip = { !Scan s -> + while( s.buf[s.x] <= ' ' ) + s.x++; + }; + // Peek a character; if matched consume it, else false. + val peek = { !Scan !s, u8 c -> + skip(s); + if( s.buf[s.x] != c ) return false; + s.x++; + return true; + }; +}; +!Scan !s = new Scan{ buf = " q"; }; +return Scan.peek(s,'q'); +"""; + + CodeGen code = new CodeGen(src).parse().opto().typeCheck(); + assertEquals("return Phi(Region,0,1);", code._stop.toString()); + assertEquals("1", Eval2.eval(code, 0)); + testCPU(src,"x86_64_v2", "Win64" ,23,null); + }; + + @Test + public void testFRefFields2() { + String src = +""" +// A hypothetical scanner class +struct Scan { + int !x; + u8[~] !buf; + // Skip whitespace + val skip = { -> + while( buf[x] <= ' ' ) + x++; + return self; + }; +}; +~Scan s = new Scan{ buf = " q"; }; +return s.skip().x; +"""; + + try { new CodeGen(src).parse().opto().typeCheck(); fail(); } + catch( Exception e ) { org.junit.Assert.assertTrue(e.getMessage().startsWith("Argument #0 isa")); } + }; + + + @Test + public void testMethod() { + String src = +""" +// A hypothetical scanner class +struct Scan { + int !x; + u8[~] !buf; + // Skip whitespace + val skip = { -> + while( buf[x] <= ' ' ) + x++; + }; + val require = { u8 ch -> + skip(); + buf[x++]==ch; + }; +}; +!Scan !s = new Scan{ buf = " [1,2]"; }; +return s.require('['); +"""; + + CodeGen code = new CodeGen(src).parse().opto().typeCheck(); + assertEquals("return (.[]==91);", code._stop.toString()); + assertEquals("1", Eval2.eval(code, 0)); + testCPU(src,"x86_64_v2", "Win64" ,4,null); + }; + + @Test + public void testSCCP0() { + String src = +""" +int x = 1; +int cnt = 5; +while (cnt) { + cnt -= 1; + if (x == 0) { + x += 1; + } +} +return x; +"""; + CodeGen code = new CodeGen(src).parse().opto().typeCheck(); + assertEquals("return 1;", code._stop.toString()); + } + + @Test + public void testSCCP1() { + String src = +""" +int x = 1; +int cnt = 5; +while( cnt-- ) + if( x == 1 ) + x = 2-x; +return x; +"""; + CodeGen code = new CodeGen(src).parse().opto().typeCheck(); + assertEquals("return 1;", code._stop.toString()); + } + +} diff --git a/src/test/java/com/seaofnodes/simple/Eval2.java b/src/test/java/com/seaofnodes/simple/Eval2.java index 908cc2e0..98e0f18a 100644 --- a/src/test/java/com/seaofnodes/simple/Eval2.java +++ b/src/test/java/com/seaofnodes/simple/Eval2.java @@ -319,14 +319,23 @@ public abstract class Eval2 { // Unknown-caller inputs are type placeholders, not heap constants. if( !tmp.isConstant() ) yield tmp; if( tmp._obj.isAry() ) { // Constant array ptr - TypeConAry con = (TypeConAry)tmp._obj.field("[]")._t; - Object[] xs = new Object[con.len()]; - for( int i=0; i<con.len(); i++ ) - xs[i] = con.at8(i); - yield xs; + Type elem = tmp._obj.field("[]")._t; + if( elem instanceof TypeConAry con ) { + Object[] xs = new Object[con.len()]; + for( int i=0; i<con.len(); i++ ) + xs[i] = con.at8(i); + yield xs; + } else { + // Generic constant array, used as a default input to a + // function; should never execute. + yield new Object[0]; + } } else { - throw Utils.TODO(); // Constant non-array ptr + // Generic TMP (since Simple is not currently making actual + // memory constants), used as a default input to a function; + // should never execute. + yield tmp.toString(); } } default -> null; diff --git a/src/test/java/com/seaofnodes/simple/MemoryEncodingTest.java b/src/test/java/com/seaofnodes/simple/MemoryEncodingTest.java index 52c0a573..e97194af 100644 --- a/src/test/java/com/seaofnodes/simple/MemoryEncodingTest.java +++ b/src/test/java/com/seaofnodes/simple/MemoryEncodingTest.java @@ -112,8 +112,7 @@ public class MemoryEncodingTest { @Test public void testEmulatedMemory() throws IOException { for( String target : new String[]{"riscv","arm"} ) for( int p=0; p<SOURCES.length; p++ ) { - CodeGen code = new CodeGen(SOURCES[p]).driver(target,"SystemV",null); - RegAllocTestSupport.checkRegisters(code); + CodeGen code = new RegAllocTestSupport.CheckedCodeGen(SOURCES[p]).driver(target,"SystemV",null); int entry=0; for( var n : code._start._outputs ) if( n instanceof FunNode fun && "main".equals(fun._name) ) diff --git a/src/test/java/com/seaofnodes/simple/MergeSortTest.java b/src/test/java/com/seaofnodes/simple/MergeSortTest.java index 39cacd98..453bd35c 100644 --- a/src/test/java/com/seaofnodes/simple/MergeSortTest.java +++ b/src/test/java/com/seaofnodes/simple/MergeSortTest.java @@ -3,8 +3,8 @@ package com.seaofnodes.simple; import com.seaofnodes.isa.eval.EvalRisc5; import com.seaofnodes.simple.codegen.CodeGen; -import com.seaofnodes.simple.util.SB; import com.seaofnodes.simple.node.cpus.riscv.riscv; +import com.seaofnodes.simple.util.SB; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -15,15 +15,54 @@ import static org.junit.Assert.fail; public class MergeSortTest { @Test public void testMergeSort0() throws IOException { + // Test merge sort on a small array of primes + String src = +""" + val merge_sort = { int[] a -> + int[] !b = new int[a#]; + copy_array (a, 0, a#, b); + split_merge(a, 0, a#, b); + }; + + val split_merge = { int[] !b, int begin, int end, int[] a -> + if (end - begin <= 1) + return 0; + int middle = (end + begin) / 2; + split_merge(a, begin, middle, b); + split_merge(a, middle, end, b); + merge(b, begin, middle, end, a); + return 0; + }; + + val merge = { int[] !b, int begin, int middle, int end, int[] a -> + int i = begin, j = middle; + + for (int k = begin; k < end; k++) { + // && and || + bool cond = false; + if (i < middle) { + if (j >= end) cond = true; + else if (a[i] <= a[j]) cond = true; + } + if (cond) b[k] = a[i++]; + else b[k] = a[j++]; + } + }; + + val copy_array = { int[] !a, int begin, int end, int[] b -> + for (int k = begin; k < end; k++) + b[k] = a[k]; + }; +"""; int[] primes = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, }; SB sb = new SB().p(primes.length).p("["); for( int prime : primes ) sb.p(prime).p(", "); String sprimes = sb.p("]").toString(); - TestC.run("sort", sprimes, 34); + TestC.run(src, "sort", null, sprimes, 34); - EvalRisc5 R5 = TestRisc5.build("src/test/java/com/seaofnodes/simple/progs", "sort", "merge_sort", 0, 36, false); + EvalRisc5 R5 = TestRisc5.build("src/test/java/com/seaofnodes/simple/progs",src, "sort", "merge_sort", 0, 36, false); // Allocate an array of primes, filled in reverse order int ps = R5._heap; R5._heap += (primes.length+1)*8; // 25 primes, and length @@ -41,7 +80,6 @@ public class MergeSortTest { assertEquals(primes[i], R5.ld8(ps+(i+1)*8)); // TODO: replace with ARM Eval - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/sort.smp")); Chapter21Test.testCPU(src,"arm", "SystemV",36,null); } } diff --git a/src/test/java/com/seaofnodes/simple/Simple.java b/src/test/java/com/seaofnodes/simple/Simple.java index aef810d1..18804ebd 100644 --- a/src/test/java/com/seaofnodes/simple/Simple.java +++ b/src/test/java/com/seaofnodes/simple/Simple.java @@ -259,7 +259,7 @@ Options: if ( !TestC.CPU_PORT.equals( cpu ) || !TestC.CALL_CONVENTION.equals( abi ) ) throw bad("cannot run code on not native target"); String exe = TestC.OS.startsWith("Windows") ? base+".exe" : base; - String result = com.seaofnodes.simple.TestC.gcc(base+".o", null, null, true, exe); + String result = TestC.gcc(base+".o", null, null, true, exe); System.out.print(result); } } diff --git a/src/test/java/com/seaofnodes/simple/SpillStats.java b/src/test/java/com/seaofnodes/simple/SpillStats.java index 6af51b33..ad044a52 100644 --- a/src/test/java/com/seaofnodes/simple/SpillStats.java +++ b/src/test/java/com/seaofnodes/simple/SpillStats.java @@ -28,7 +28,8 @@ public class SpillStats extends RunListener { // The same native helpers serve old and new program cohorts. public static void recordNative(CodeGen code, String cpu, String abi) { - String cohort = ACTIVE!=null && ACTIVE._test.getTestClass()==Chapter23Test.class + String cohort = ACTIVE!=null && (ACTIVE._test.getTestClass()==Chapter24Test.class || ACTIVE._test.getTestClass()==Chapter24AllocTest.class) + ? "Chapter24" : ACTIVE!=null && ACTIVE._test.getTestClass()==Chapter23Test.class ? "Chapter23" : ACTIVE!=null && ACTIVE._test.getTestClass()==Chapter22Test.class ? "Chapter22" : "Chapter21"; record(code,cohort,cpu,abi); @@ -47,7 +48,7 @@ public class SpillStats extends RunListener { } public static void main(String[] args) throws ClassNotFoundException { - if( args.length==0 ) args = new String[]{"Chapter20Test","Chapter21Test","Chapter21AllocTest","Chapter22Test","Chapter23Test","Chapter23AllocTest","BrainFuckTest","MergeSortTest"}; + if( args.length==0 ) args = new String[]{"Chapter20Test","Chapter21Test","Chapter21AllocTest","Chapter22Test","Chapter23Test","Chapter23AllocTest","Chapter24Test","Chapter24AllocTest","BrainFuckTest","MergeSortTest"}; Class<?>[] tests = new Class<?>[args.length]; for( int i=0; i<args.length; i++ ) tests[i] = Class.forName("com.seaofnodes.simple."+args[i]); diff --git a/src/test/java/com/seaofnodes/simple/TestArm64.java b/src/test/java/com/seaofnodes/simple/TestArm64.java index a22063eb..086bf9c7 100644 --- a/src/test/java/com/seaofnodes/simple/TestArm64.java +++ b/src/test/java/com/seaofnodes/simple/TestArm64.java @@ -18,13 +18,19 @@ import static org.junit.Assert.assertEquals; public class TestArm64 { public static EvalArm64 build( String file, int arg, int spills, boolean print ) throws IOException { - return build("src/test/java/com/seaofnodes/simple/progs",file, arg, spills, print); + String dir = "src/test/java/com/seaofnodes/simple/progs"; + String src = Files.readString(Path.of(dir + "/"+file+".smp")); + return build(dir,src, file, arg, spills, print); + } + + public static EvalArm64 build( String name, String src, int arg, int spills, boolean print ) throws IOException { + String dir = "src/test/java/com/seaofnodes/simple/progs"; + return build(dir, src ,name, arg, spills, print); } // Compile and run a simple program - public static EvalArm64 build( String dir, String file, int arg, int spills, boolean print ) throws IOException { + public static EvalArm64 build( String dir, String src, String file, int arg, int spills, boolean print ) throws IOException { // Compile and export Simple - String src = Files.readString(Path.of(dir+"/"+file+".smp")); CodeGen code = new CheckedCodeGen(src).driver("arm", "SystemV",null); SpillStats.recordNative(code,"arm","SystemV"); if( print ) { code.print_as_hex(); System.out.print(code.asm()); } diff --git a/src/test/java/com/seaofnodes/simple/TestC.java b/src/test/java/com/seaofnodes/simple/TestC.java index 2e61211a..3b3aabc0 100644 --- a/src/test/java/com/seaofnodes/simple/TestC.java +++ b/src/test/java/com/seaofnodes/simple/TestC.java @@ -41,14 +41,31 @@ public abstract class TestC { String src = Files.readString(Path.of(sfile)); run(src,CALL_CONVENTION,arg, "",standalone? null: cfile,efile,"S",expected,spills); } + + // link with c and also inline + public static void run(String src, String file, TypeInteger arg, String expected, int spills) throws IOException { + String dir = "src/test/java/com/seaofnodes/simple/progs"; + String cfile = dir+"/"+file+".c"; + String efile = "build/objs/"+file; + run(src, CALL_CONVENTION, arg, "", cfile, efile, "S", expected, spills); + } + public static void run(String dir, String file, String expected, int spills ) throws IOException { run(dir, file,null, expected, spills, false); } + // Do not link with c file - no inline. public static void runS(String file, String expected, int spills ) throws IOException { run("src/test/java/com/seaofnodes/simple/progs", file, null, expected, spills, true); } + + // Do not link with c file - just inline with source. + public static void runSF(String name, String src, TypeInteger arg, String expected, int spills ) throws IOException { + String efile = "build/objs/"+name; + run(src,CALL_CONVENTION,arg, "",null,efile,"S",expected,spills); + } + public static void runS(String file, TypeInteger arg, String expected, int spills ) throws IOException { run("src/test/java/com/seaofnodes/simple/progs", file, arg, expected, spills, true); } diff --git a/src/test/java/com/seaofnodes/simple/TestRisc5.java b/src/test/java/com/seaofnodes/simple/TestRisc5.java index ace2a7ea..f55e7d0b 100644 --- a/src/test/java/com/seaofnodes/simple/TestRisc5.java +++ b/src/test/java/com/seaofnodes/simple/TestRisc5.java @@ -16,13 +16,19 @@ import static org.junit.Assert.*; public abstract class TestRisc5 { public static EvalRisc5 build( String file, int arg, int spills, boolean print ) throws IOException { - return build("src/test/java/com/seaofnodes/simple/progs",file, null, arg, spills, print); + String dir = "src/test/java/com/seaofnodes/simple/progs"; + String src = Files.readString(Path.of(dir + "/"+file+".smp")); + return build(dir,src, file, null, arg, spills, print); + } + + public static EvalRisc5 build( String name, String src, int arg, int spills, boolean print ) throws IOException { + String dir = "src/test/java/com/seaofnodes/simple/progs"; + return build(dir, src ,name, null, arg, spills, print); } // Compile and run a simple program - public static EvalRisc5 build( String dir, String file, String main, int arg, int spills, boolean print ) throws IOException { + public static EvalRisc5 build( String dir, String src, String file, String main, int arg, int spills, boolean print ) throws IOException { // Compile and export Simple - String src = Files.readString(Path.of(dir+"/"+file+".smp")); CodeGen code = new CheckedCodeGen(src).driver("riscv", "SystemV",null); SpillStats.recordNative(code,"riscv","SystemV"); if( print ) { code.print_as_hex(); System.out.print(code.asm()); } diff --git a/src/test/java/com/seaofnodes/simple/TypeTest.java b/src/test/java/com/seaofnodes/simple/TypeTest.java index b21af9ee..fd3fea9d 100644 --- a/src/test/java/com/seaofnodes/simple/TypeTest.java +++ b/src/test/java/com/seaofnodes/simple/TypeTest.java @@ -7,6 +7,22 @@ import static org.junit.Assert.assertSame; public class TypeTest { + // Removing zero must not reset the widening history of a remaining range. + @Test public void testNonZeroWidening() { + for( byte widen=0; widen<=3; widen++ ) { + TypeInteger pos = TypeInteger.make(0,255,widen).nonZero(); + TypeInteger neg = TypeInteger.make(-255,0,widen).nonZero(); + Assert.assertEquals("positive range widening",widen,pos._widen); + Assert.assertEquals("negative range widening",widen,neg._widen); + assertSame(TypeInteger.make(1,255,widen),pos); + assertSame(TypeInteger.make(-255,-1,widen),neg); + // Singleton ranges retain their widening level too. + assertSame(TypeInteger.make(1,1,widen),TypeInteger.make(0,1,widen).nonZero()); + assertSame(TypeInteger.make(-1,-1,widen),TypeInteger.make(-1,0,widen).nonZero()); + } + Assert.assertNull(TypeInteger.ZERO.nonZero()); + } + // Struct hashes omit field types, so interning compares unlike leaf kinds. @Test public void testCyclicLeafKinds() { diff --git a/src/test/java/com/seaofnodes/simple/codegen/RegAllocTestSupport.java b/src/test/java/com/seaofnodes/simple/codegen/RegAllocTestSupport.java index ad898be3..1ffdb3d0 100644 --- a/src/test/java/com/seaofnodes/simple/codegen/RegAllocTestSupport.java +++ b/src/test/java/com/seaofnodes/simple/codegen/RegAllocTestSupport.java @@ -244,6 +244,33 @@ public class RegAllocTestSupport { assertFalse("A fixed definition clobbers even before coloring",uncolored.sameBlockNoClobber(copy)); } + public static void coldLoopSelfConflict() { + for( boolean phiConflict : new boolean[]{false,true} ) { + CodeGen code = graph(); + RegAlloc alloc = new RegAlloc(code); + Op init = new Op(A,null,null,false,code._start); + LoopNode loop = new LoopNode(null,code._start); + PhiNode phi = new PhiNode("loop",TypeInteger.BOT,loop,init,null); + Op back = new Op(A,A,null,false,loop,phi); + phi.setDef(2,back); + Op use = new Op(null,A,null,false,loop,phi); + loop.setDef(2,loop); + LRG lrg = alloc.newLRG(phi); + lrg._mask = A; + alloc.union(lrg,init); alloc.union(lrg,back); + lrg.selfConflict(back); + if( phiConflict ) lrg.selfConflict(phi); + assertTrue(alloc.splitSelfConflict((byte)0,lrg)); + assertSame(phi,use.in(1)); // First try leaves the hot definition alone. + assertSame(back,phi.in(2)); + if( phiConflict ) assertTrue(phi.in(1) instanceof SplitNode); + // Even if the first attempt made no graph change, retry must split. + assertTrue(alloc.splitSelfConflict((byte)1,lrg)); + assertTrue(phi.in(2) instanceof SplitNode); + if( phiConflict ) assertTrue(use.in(1) instanceof SplitNode); + } + } + public static void copyForward() throws Exception { // Forwarding, fixed operand, two-address tie, intervening clobber, // another user, and a scheduling-only edge. diff --git a/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java b/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java index fee0f2a8..c837bd6f 100644 --- a/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java +++ b/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java @@ -594,7 +594,7 @@ public class Scheduler { * @param start The start node * @return The final schedule. */ - public static Scheduler.Block schedule(StartNode start) { + public static Block schedule(StartNode start) { var scheduler = new Scheduler(); scheduler.doMarkAlive(start); scheduler.doBuildCTF(start); diff --git a/src/test/java/com/seaofnodes/simple/fuzzer/Reducer.java b/src/test/java/com/seaofnodes/simple/fuzzer/Reducer.java index 856e6a24..f6e12e11 100644 --- a/src/test/java/com/seaofnodes/simple/fuzzer/Reducer.java +++ b/src/test/java/com/seaofnodes/simple/fuzzer/Reducer.java @@ -174,4 +174,4 @@ public class Reducer { }); } -} +}
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java b/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java index 6ec066e9..20815d5d 100644 --- a/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java +++ b/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java @@ -440,7 +440,7 @@ public class ScriptGenerator { int idx = random.nextInt(forwardStructs.size()+10); TypeStruct struct; if (idx < 10) { - var name = getStructName(); + var name = getStructName(); struct = new TypeStruct(name); forwardStructs.add(struct); } else { @@ -937,4 +937,4 @@ public class ScriptGenerator { else sb.append(v.name); } -} +}
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/and1.smp b/src/test/java/com/seaofnodes/simple/progs/and1.smp deleted file mode 100644 index ef4c904f..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/and1.smp +++ /dev/null @@ -1,10 +0,0 @@ -// -*- mode: java; -*- -int a = 1; -int b = 1; - -if(a && b) { - sys.io.p("And"); -} else { - sys.io.p("Or"); -} -return 0; diff --git a/src/test/java/com/seaofnodes/simple/progs/and2.smp b/src/test/java/com/seaofnodes/simple/progs/and2.smp deleted file mode 100644 index 2a463c94..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/and2.smp +++ /dev/null @@ -1,16 +0,0 @@ -// -*- mode: java; -*- -int a = 1; -int b = 1; - -int x=1; -int y=1; -int z=0; - -int g = x++ && y++ && z++; - -if(x == 2 && y == 2 && z == 1 && g == 0) { - sys.io.p("Effected"); -} else { - sys.io.p("Not effected"); -} -return 0; diff --git a/src/test/java/com/seaofnodes/simple/progs/and3.smp b/src/test/java/com/seaofnodes/simple/progs/and3.smp deleted file mode 100644 index aadbdfed..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/and3.smp +++ /dev/null @@ -1,14 +0,0 @@ -// -*- mode: java; -*- -int a = 1; -int b = 1; - -var sq = { int x -> - x*x; -}; - -if(a && sq(0)) { - sys.io.p("And"); -} else { - sys.io.p("Or"); -} -return 0; diff --git a/src/test/java/com/seaofnodes/simple/progs/antiDep1.smp b/src/test/java/com/seaofnodes/simple/progs/antiDep1.smp deleted file mode 100644 index 52bfe29b..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/antiDep1.smp +++ /dev/null @@ -1,11 +0,0 @@ -// -*- mode: java; -*- -struct S { int f; }; -var v0 = new S; -!S? !v1; -if (arg) v1 = new S; -if (v1) { - v0.f = v1.f; -} else { - v0.f = 2; -} -return v0; diff --git a/src/test/java/com/seaofnodes/simple/progs/brain_fuck.smp b/src/test/java/com/seaofnodes/simple/progs/brain_fuck.smp deleted file mode 100644 index ed90cb84..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/brain_fuck.smp +++ /dev/null @@ -1,46 +0,0 @@ -// -*- mode: java; -*- -val brain_fuck = { -> - u8[] !program = new u8[106];program[0] = 43;program[1] = 43;program[2] = 43;program[3] = 43;program[4] = 43;program[5] = 43;program[6] = 43;program[7] = 43;program[8] = 91;program[9] = 62;program[10] = 43;program[11] = 43;program[12] = 43;program[13] = 43;program[14] = 91;program[15] = 62;program[16] = 43;program[17] = 43;program[18] = 62;program[19] = 43;program[20] = 43;program[21] = 43;program[22] = 62;program[23] = 43;program[24] = 43;program[25] = 43;program[26] = 62;program[27] = 43;program[28] = 60;program[29] = 60;program[30] = 60;program[31] = 60;program[32] = 45;program[33] = 93;program[34] = 62;program[35] = 43;program[36] = 62;program[37] = 43;program[38] = 62;program[39] = 45;program[40] = 62;program[41] = 62;program[42] = 43;program[43] = 91;program[44] = 60;program[45] = 93;program[46] = 60;program[47] = 45;program[48] = 93;program[49] = 62;program[50] = 62;program[51] = 46;program[52] = 62;program[53] = 45;program[54] = 45;program[55] = 45;program[56] = 46;program[57] = 43;program[58] = 43;program[59] = 43;program[60] = 43;program[61] = 43;program[62] = 43;program[63] = 43;program[64] = 46;program[65] = 46;program[66] = 43;program[67] = 43;program[68] = 43;program[69] = 46;program[70] = 62;program[71] = 62;program[72] = 46;program[73] = 60;program[74] = 45;program[75] = 46;program[76] = 60;program[77] = 46;program[78] = 43;program[79] = 43;program[80] = 43;program[81] = 46;program[82] = 45;program[83] = 45;program[84] = 45;program[85] = 45;program[86] = 45;program[87] = 45;program[88] = 46;program[89] = 45;program[90] = 45;program[91] = 45;program[92] = 45;program[93] = 45;program[94] = 45;program[95] = 45;program[96] = 45;program[97] = 46;program[98] = 62;program[99] = 62;program[100] = 43;program[101] = 46;program[102] = 62;program[103] = 43;program[104] = 43;program[105] = 46; - int d = 0; - u8[] !output = new u8[0]; - u8[] !data = new u8[100]; - - for( int pc = 0; pc < program#; pc++ ) { - var command = program[pc]; - if (command == 62) { - d++; - } else if (command == 60) { - d--; - } else if (command == 43) { - data[d]++; - } else if (command == 45) { - data[d]--; - } else if (command == 46) { - // Output a byte; increase the output array size - var old = output; - output = new u8[output# + 1]; - for( int i = 0; i < old#; i++ ) - output[i] = old[i]; - output[old#] = data[d]; // Add the extra byte on the end - } else if (command == 44) { - data[d] = 42; - } else if (command == 91) { - if (data[d] == 0) { - for( int d = 1; d > 0; ) { - command = program[++pc]; - if (command == 91) d++; - if (command == 93) d--; - } - } - } else if (command == 93) { - if (data[d]) { - for( int d = 1; d > 0; ) { - command = program[--pc]; - if (command == 93) d++; - if (command == 91) d--; - } - } - } - } - return output; -}; diff --git a/src/test/java/com/seaofnodes/simple/progs/echo.smp b/src/test/java/com/seaofnodes/simple/progs/echo.smp deleted file mode 100644 index 8eafd73b..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/echo.smp +++ /dev/null @@ -1,3 +0,0 @@ -// -*- mode: java; -*- -// Echo stdin to stdout. -return sys.io.p( sys.io.stdin() ); diff --git a/src/test/java/com/seaofnodes/simple/progs/fib.smp b/src/test/java/com/seaofnodes/simple/progs/fib.smp deleted file mode 100644 index 1512541b..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/fib.smp +++ /dev/null @@ -1,11 +0,0 @@ -// -*- mode: java; -*- -val fib = {int n -> - int f1=1; - int f2=1; - while( n-- > 1 ){ - int temp = f1+f2; - f1=f2; - f2=temp; - } - return f2; -};
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/large.smp b/src/test/java/com/seaofnodes/simple/progs/large.smp deleted file mode 100644 index 73271e66..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/large.smp +++ /dev/null @@ -1,5344 +0,0 @@ - -struct stbi_io_callbacks { - { i64 u8[] int -> int } read = "C"; // fill 'data' with 'size' bytes. return number of bytes actually read - { i64 int -> int } skip = "C"; // skip the next 'n' bytes, or 'unget' the last -n bytes if negative - { i64 -> int } eof = "C"; // returns nonzero if we are at end of file/data -}; - -struct stbi__context { - u32 img_x, img_y; - int img_n, img_out_n; - - !stbi_io_callbacks !io; - u8[]io_user_data; - - int read_from_callbacks; - int buflen; - u8[] buffer_start; - int callback_already_read; - - u8[] img_buffer; - int img_buffer_end; - u8[] img_buffer_original; - int img_buffer_original_end; -}; - -{ stbi__context -> u8 } stbi__get8 = "C"; - -val sample = { !stbi__context !s, int pal_len -> - var palette = new u8[1024]; - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - - return palette; -}; diff --git a/src/test/java/com/seaofnodes/simple/progs/loop2.smp b/src/test/java/com/seaofnodes/simple/progs/loop2.smp deleted file mode 100644 index 01ec827e..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/loop2.smp +++ /dev/null @@ -1,10 +0,0 @@ -// -*- mode: java; -*- -int i = 0; -while(true) { - i += 1; - if( i==0 ) continue; - if( i==1 ) continue; - if( i==2 ) break; - continue; -} -return i; diff --git a/src/test/java/com/seaofnodes/simple/progs/or1.smp b/src/test/java/com/seaofnodes/simple/progs/or1.smp deleted file mode 100644 index f5f526c3..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/or1.smp +++ /dev/null @@ -1,12 +0,0 @@ -// -*- mode: java; -*- -int a = 1; -int b = 0; - -if(a++ || b++ ) { - if(b == 0 && a == 2) { - sys.io.p("Or"); - } -} else{ - sys.io.p("And"); -} -return 0; diff --git a/src/test/java/com/seaofnodes/simple/progs/or2.smp b/src/test/java/com/seaofnodes/simple/progs/or2.smp deleted file mode 100644 index ac688b5a..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/or2.smp +++ /dev/null @@ -1,23 +0,0 @@ -// -*- mode: java; -*- -int a = 1; -int b = 1; - -int x = -1; -int y=1; -int z= -1; - -int g = x++ || y++ || z++; - -int switch = 0; -if(x == 4 || y == 4 || z == 4) { - switch = -1; -} else { - switch = 1; -} -int cd = 1; -if((x == 0 && y == 1 && z==-1) && switch && g) { - sys.io.p("Effected"); -} else { - sys.io.p("Not effected"); -} -return 0; diff --git a/src/test/java/com/seaofnodes/simple/progs/person.smp b/src/test/java/com/seaofnodes/simple/progs/person.smp deleted file mode 100644 index 94e2cdde..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/person.smp +++ /dev/null @@ -1,9 +0,0 @@ -// -*-java-*- -struct Person { - i32 age; -}; - -val fcn = { !Person?[] ps, int x -> - if( ps[x] ) - ps[x].age++; -};
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/print.smp b/src/test/java/com/seaofnodes/simple/progs/print.smp deleted file mode 100644 index 3bb86268..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/print.smp +++ /dev/null @@ -1,8 +0,0 @@ -int x = 1; - -int y = 2; -if(x == 1) { -y = 1; -} - -return y;
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/ptrand.smp b/src/test/java/com/seaofnodes/simple/progs/ptrand.smp deleted file mode 100644 index 8b8af571..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/ptrand.smp +++ /dev/null @@ -1,10 +0,0 @@ -struct S { !S? !fld; }; - -val ptr = arg == 1 ? null : new S{fld = arg==1 ? null : new S{fld = null;};}; -if( ptr && ptr.fld ) { - sys.io.p("true"); -} else { - sys.io.p("false"); -} - -return 0; diff --git a/src/test/java/com/seaofnodes/simple/progs/riscv_load.smp b/src/test/java/com/seaofnodes/simple/progs/riscv_load.smp deleted file mode 100644 index 1a36fb99..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/riscv_load.smp +++ /dev/null @@ -1,4 +0,0 @@ -struct Person { i32 age;}; -!Person !p = new Person; -p.age += arg; -return p.age; diff --git a/src/test/java/com/seaofnodes/simple/progs/sext_str_1.smp b/src/test/java/com/seaofnodes/simple/progs/sext_str_1.smp deleted file mode 100644 index 57b37477..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/sext_str_1.smp +++ /dev/null @@ -1,4 +0,0 @@ -struct Person {i64 age;} -!Person !p = new Person; -p.age += arg; -return p.age; diff --git a/src/test/java/com/seaofnodes/simple/progs/sext_str_fold_away.smp b/src/test/java/com/seaofnodes/simple/progs/sext_str_fold_away.smp deleted file mode 100644 index 7d7fdce7..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/sext_str_fold_away.smp +++ /dev/null @@ -1,5 +0,0 @@ -// Should fold away sign extend -struct Person { i8 age;}; -!Person !p = new Person; -p.age = (arg<<48)>>48; -return 0;
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/sext_str_not_fold_away.smp b/src/test/java/com/seaofnodes/simple/progs/sext_str_not_fold_away.smp deleted file mode 100644 index 4d6ca3a3..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/sext_str_not_fold_away.smp +++ /dev/null @@ -1,4 +0,0 @@ -struct Person { i32 age;}; -!Person !p = new Person; -p.age = (arg<<17)>>17; -return 0;
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/sext_str_not_fold_away_2.smp b/src/test/java/com/seaofnodes/simple/progs/sext_str_not_fold_away_2.smp deleted file mode 100644 index 5c96c060..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/sext_str_not_fold_away_2.smp +++ /dev/null @@ -1,4 +0,0 @@ -struct Person { i32 age;}; -!Person !p = new Person; -p.age = (arg<<48)>>48; -return 0;
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/sieve.smp b/src/test/java/com/seaofnodes/simple/progs/sieve.smp deleted file mode 100644 index 569dbb96..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/sieve.smp +++ /dev/null @@ -1,31 +0,0 @@ -// -*- mode: java; -*- -val sieve = { int N -> - // The main Sieve array - bool[] !ary = new bool[N]; - // The primes less than N - u32[] !primes = new u32[N>>1]; - // Number of primes so far, searching at index p - int nprimes = 0, p=2; - // Find primes while p^2 < N - while( p*p < N ) { - // skip marked non-primes - while( ary[p] ) p++; - // p is now a prime - primes[nprimes++] = p; - // Mark out the rest non-primes - for( int i = p + p; i < ary#; i+= p ) - ary[i] = true; - p++; - } - - // Now just collect the remaining primes, no more marking - for( ; p < N; p++ ) - if( !ary[p] ) - primes[nprimes++] = p; - - // Copy/shrink the result array - u32[] !rez = new u32[nprimes]; - for( int j=0; j < nprimes; j++ ) - rez[j] = primes[j]; - return rez; -}; diff --git a/src/test/java/com/seaofnodes/simple/progs/sort.smp b/src/test/java/com/seaofnodes/simple/progs/sort.smp deleted file mode 100644 index ae3f4f23..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/sort.smp +++ /dev/null @@ -1,38 +0,0 @@ -// -*- mode: java; -*- -// based on the top-down version from https://en.wikipedia.org/wiki/Merge_sort - -val merge_sort = { int[] a -> - int[] !b = new int[a#]; - copy_array (a, 0, a#, b); - split_merge(a, 0, a#, b); -}; - -val split_merge = { int[] b, int begin, int end, int[] a -> - if (end - begin <= 1) - return 0; - int middle = (end + begin) / 2; - split_merge(a, begin, middle, b); - split_merge(a, middle, end, b); - merge(b, begin, middle, end, a); - return 0; -}; - -val merge = { int[] b, int begin, int middle, int end, int[] a -> - int i = begin, j = middle; - - for (int k = begin; k < end; k++) { - // && and || - bool cond = false; - if (i < middle) { - if (j >= end) cond = true; - else if (a[i] <= a[j]) cond = true; - } - if (cond) b[k] = a[i++]; - else b[k] = a[j++]; - } -}; - -val copy_array = { int[] a, int begin, int end, int[] b -> - for (int k = begin; k < end; k++) - b[k] = a[k]; -}; diff --git a/src/test/java/com/seaofnodes/simple/progs/stacked_r_10x.c b/src/test/java/com/seaofnodes/simple/progs/stacked_r_10x.c new file mode 100644 index 00000000..d44d5387 --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/progs/stacked_r_10x.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> + +__attribute__ ((CALL_CONV)) +extern int stack10(int x); + +int main() { +int result = stack10(0); + +printf("%d", result); +return 0; +}
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/stacked_r_11x.c b/src/test/java/com/seaofnodes/simple/progs/stacked_r_11x.c new file mode 100644 index 00000000..d71979d1 --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/progs/stacked_r_11x.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> + +__attribute__ ((CALL_CONV)) +extern int stack11(int x); + +int main() { +int result = stack11(1); + +printf("%d", result); +return 0; +}
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/stacked_r_12x.c b/src/test/java/com/seaofnodes/simple/progs/stacked_r_12x.c new file mode 100644 index 00000000..a4e425cb --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/progs/stacked_r_12x.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> + +__attribute__ ((CALL_CONV)) +extern int stack12(int x); + +int main() { +int result = stack12(0); + +printf("%d", result); +return 0; +}
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/stacked_r_13x.c b/src/test/java/com/seaofnodes/simple/progs/stacked_r_13x.c new file mode 100644 index 00000000..a3a51d0e --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/progs/stacked_r_13x.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> + +__attribute__ ((CALL_CONV)) +extern int stack13(int x); + +int main() { +int result = stack13(0); + +printf("%d", result); +return 0; +}
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/stacked_r_9x.c b/src/test/java/com/seaofnodes/simple/progs/stacked_r_9x.c new file mode 100644 index 00000000..4f93ba24 --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/progs/stacked_r_9x.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> + +__attribute__ ((CALL_CONV)) +extern int stack9(int x); + +int main() { +int result = stack9(0); + +printf("%d", result); +return 0; +}
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/store_peep.smp b/src/test/java/com/seaofnodes/simple/progs/store_peep.smp deleted file mode 100644 index c3feddd5..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/store_peep.smp +++ /dev/null @@ -1,3 +0,0 @@ -i64 a = 123456789012345; -i32 b = a; // truncate high order bits -return b;
\ No newline at end of file |
