<commit_before>package gcil

import (
	"bufio"
	"bytes"
	"fmt"
	"github.com/rhysd/gocaml/alpha"
	"github.com/rhysd/gocaml/lexer"
	"github.com/rhysd/gocaml/parser"
	"github.com/rhysd/gocaml/token"
	"github.com/rhysd/gocaml/typing"
	"strings"
	"testing"
)

func TestEmitInsn(t *testing.T) {
	cases := []struct {
		what     string
		code     string
		expected []string
	}{
		{
			"int",
			"42",
			[]string{"int 42 ; type=int"},
		},
		{
			"unit",
			"()",
			[]string{"unit ; type=()"},
		},
		{
			"float",
			"3.14",
			[]string{"float 3.140000 ; type=float"},
		},
		{
			"boolean",
			"false",
			[]string{"bool false ; type=bool"},
		},
		{
			"unary relational op",
			"not true",
			[]string{
				"bool true ; type=bool",
				"unary not $k1 ; type=bool",
			},
		},
		{
			"unary arithmetic op",
			"-42",
			[]string{
				"int 42 ; type=int",
				"unary - $k1 ; type=int",
			},
		},
		{
			"binary int op",
			"1 + 2",
			[]string{
				"int 1 ; type=int",
				"int 2 ; type=int",
				"binary + $k1 $k2 ; type=int",
			},
		},
		{
			"binary float op",
			"3.14 *. 2.0",
			[]string{
				"float 3.140000 ; type=float",
				"float 2.000000 ; type=float",
				"binary *. $k1 $k2 ; type=float",
			},
		},
		{
			"binary relational op",
			"1 < 2",
			[]string{
				"int 1 ; type=int",
				"int 2 ; type=int",
				"binary < $k1 $k2 ; type=bool",
			},
		},
	}
<commit_msg>add more tests for GCIL instructions<commit_after>package gcil

import (
	"bufio"
	"bytes"
	"fmt"
	"github.com/rhysd/gocaml/alpha"
	"github.com/rhysd/gocaml/lexer"
	"github.com/rhysd/gocaml/parser"
	"github.com/rhysd/gocaml/token"
	"github.com/rhysd/gocaml/typing"
	"strings"
	"testing"
)

func TestEmitInsn(t *testing.T) {
	cases := []struct {
		what     string
		code     string
		expected []string
	}{
		{
			"int",
			"42",
			[]string{"int 42 ; type=int"},
		},
		{
			"unit",
			"()",
			[]string{"unit ; type=()"},
		},
		{
			"float",
			"3.14",
			[]string{"float 3.140000 ; type=float"},
		},
		{
			"boolean",
			"false",
			[]string{"bool false ; type=bool"},
		},
		{
			"unary relational op",
			"not true",
			[]string{
				"bool true ; type=bool",
				"unary not $k1 ; type=bool",
			},
		},
		{
			"unary arithmetic op",
			"-42",
			[]string{
				"int 42 ; type=int",
				"unary - $k1 ; type=int",
			},
		},
		{
			"binary int op",
			"1 + 2",
			[]string{
				"int 1 ; type=int",
				"int 2 ; type=int",
				"binary + $k1 $k2 ; type=int",
			},
		},
		{
			"binary float op",
			"3.14 *. 2.0",
			[]string{
				"float 3.140000 ; type=float",
				"float 2.000000 ; type=float",
				"binary *. $k1 $k2 ; type=float",
			},
		},
		{
			"binary relational op",
			"1 < 2",
			[]string{
				"int 1 ; type=int",
				"int 2 ; type=int",
				"binary < $k1 $k2 ; type=bool",
			},
		},
		{
			"if expression",
			"if 1 < 2 then 3 else 4",
			[]string{
				"int 1 ; type=int",
				"int 2 ; type=int",
				"binary < $k1 $k2 ; type=bool",
				"if $k3",
				"BEGIN: then",
				"int 3 ; type=int",
				"END: then",
				"BEGIN: else",
				"int 4 ; type=int",
				"END: else",
			},
		},
		{
			"let expression and variable reference",
			"let a = 1 in let b = a in b",
			[]string{
				"int 1 ; type=int",
				"ref a$t1 ; type=int",
				"ref b$t2 ; type=int",
			},
		},
		{
			"function and its application",
			"let rec f a = a + 1 in f 3",
			[]string{
				"fun a$t2",
				"BEGIN: body (f$t1)",
				"ref a$t2 ; type=int",
				"int 1 ; type=int",
				"binary + $k1 $k2 ; type=int",
				"END: body (f$t1)",
				"; type=int -> int",
				"ref f$t1 ; type=int -> int",
				"int 3 ; type=int",
				"app $k4 $k5 ; type=int",
			},
		},
		{
			"tuple literal",
			"(1, 2, 3)",
			[]string{
				"int 1 ; type=int",
				"int 2 ; type=int",
				"int 3 ; type=int",
				"tuple $k1,$k2,$k3 ; type=(int, int, int)",
			},
		},
		{
			"let tuple substitution",
			"let (a, b) = (1, 2) in a + b",
			[]string{
				"int 1 ; type=int",
				"int 2 ; type=int",
				"tuple $k1,$k2 ; type=(int, int)",
				"tplload 0 $k3 ; type=int",
				"tplload 1 $k3 ; type=int",
				"ref a$t1 ; type=int",
				"ref b$t2 ; type=int",
				"binary + $k4 $k5 ; type=int",
			},
		},
		{
			"array creation",
			"Array.create 3 true",
			[]string{
				"int 3 ; type=int",
				"bool true ; type=bool",
				"array $k1 $k2 ; type=bool array",
			},
		},
		{
			"access to array",
			"let a = Array.create 3 true in a.(1)",
			[]string{
				"int 3 ; type=int",
				"bool true ; type=bool",
				"array $k1 $k2 ; type=bool array",
				"ref a$t1 ; type=bool array",
				"int 1 ; type=int",
				"arrload $k5 $k4 ; type=bool",
			},
		},
		{
			"modify element of array",
			"let a = Array.create 3 true in a.(1) <- false",
			[]string{
				"int 3 ; type=int",
				"bool true ; type=bool",
				"array $k1 $k2 ; type=bool array",
				"ref a$t1 ; type=bool array",
				"int 1 ; type=int",
				"bool false ; type=bool",
				"arrstore $k5 $k4 $k6 ; type=bool",
			},
		},
	}

{'fraction_non_alphanumeric': 0.2110839445802771, 'fraction_numerical': 0.03667481662591687, 'mean_word_length': 2.2553050397877983, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4782701', 'n_tokens_mistral': 2684, 'n_tokens_neox': 2092, 'n_words': 487}