From 37aa1ef070421be8a588bd675c1cc19b044adf0e Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sun, 27 Aug 2023 16:11:33 -0400 Subject: [PATCH 01/22] Fatal-on-data-error `mlr -x` option [WIP] --- internal/pkg/cli/option_parse.go | 9 +++++ internal/pkg/cli/option_types.go | 3 ++ internal/pkg/mlrval/mlrval_is.go | 8 ++++ internal/pkg/mlrval/mlrval_type.go | 1 + internal/pkg/output/channel_writer.go | 45 +++++++++++++++++++-- internal/pkg/output/file_output_handlers.go | 35 +++++++++++----- internal/pkg/stream/stream.go | 19 ++++++--- 7 files changed, 100 insertions(+), 20 deletions(-) diff --git a/internal/pkg/cli/option_parse.go b/internal/pkg/cli/option_parse.go index 0ee362f2b3..8bd7db122e 100644 --- a/internal/pkg/cli/option_parse.go +++ b/internal/pkg/cli/option_parse.go @@ -2711,6 +2711,15 @@ var MiscFlagSection = FlagSection{ infoPrinter: MiscPrintInfo, flags: []Flag{ + { + name: "-x", + help: "If any record has an error value in it, report it and stop the process. The default is to print the field value as `(error)` and continue.", + parser: func(args []string, argc int, pargi *int, options *TOptions) { + options.WriterOptions.FatalOnErrorData = true + *pargi += 1 + }, + }, + { name: "-n", help: "Process no input files, nor standard input either. Useful for `mlr put` with `begin`/`end` statements only. (Same as `--from /dev/null`.) Also useful in `mlr -n put -v '...'` for analyzing abstract syntax trees (if that's your thing).", diff --git a/internal/pkg/cli/option_types.go b/internal/pkg/cli/option_types.go index 06f71ad278..96ff3983af 100644 --- a/internal/pkg/cli/option_types.go +++ b/internal/pkg/cli/option_types.go @@ -135,6 +135,9 @@ type TWriterOptions struct { // For floating-point numbers: "" means use the Go default. FPOFMT string + + // Fatal the process when error data in a given record is about to be output. + FatalOnErrorData bool } // ---------------------------------------------------------------- diff --git a/internal/pkg/mlrval/mlrval_is.go b/internal/pkg/mlrval/mlrval_is.go index 900b0e985a..d1593776e5 100644 --- a/internal/pkg/mlrval/mlrval_is.go +++ b/internal/pkg/mlrval/mlrval_is.go @@ -23,6 +23,14 @@ func (mv *Mlrval) IsError() bool { return mv.Type() == MT_ERROR } +func (mv *Mlrval) GetError() (bool, error) { + if mv.Type() == MT_ERROR { + return true, mv.err + } else { + return false, nil + } +} + // TODO: comment no JIT-infer here -- absent is non-inferrable and we needn't take the expense of JIT. func (mv *Mlrval) IsAbsent() bool { return mv.mvtype == MT_ABSENT diff --git a/internal/pkg/mlrval/mlrval_type.go b/internal/pkg/mlrval/mlrval_type.go index ace7805ddb..e47f73b8e7 100644 --- a/internal/pkg/mlrval/mlrval_type.go +++ b/internal/pkg/mlrval/mlrval_type.go @@ -56,6 +56,7 @@ package mlrval type Mlrval struct { printrep string intf interface{} + err error // Payload for MT_ERROR types printrepValid bool // Enumeration for string / int / float / boolean / etc. // I would call this "type" not "mvtype" but "type" is a keyword in Go. diff --git a/internal/pkg/output/channel_writer.go b/internal/pkg/output/channel_writer.go index 061583ed51..e00e094b4b 100644 --- a/internal/pkg/output/channel_writer.go +++ b/internal/pkg/output/channel_writer.go @@ -3,6 +3,8 @@ package output import ( "bufio" "container/list" + "fmt" + "os" "github.com/johnkerl/miller/internal/pkg/cli" "github.com/johnkerl/miller/internal/pkg/types" @@ -13,19 +15,26 @@ func ChannelWriter( recordWriter IRecordWriter, writerOptions *cli.TWriterOptions, doneChannel chan<- bool, + erroredChannel chan<- bool, bufferedOutputStream *bufio.Writer, outputIsStdout bool, ) { for { recordsAndContexts := <-writerChannel - done := channelWriterHandleBatch( + done, errored := channelWriterHandleBatch( recordsAndContexts, recordWriter, writerOptions, + erroredChannel, bufferedOutputStream, outputIsStdout, ) + if errored { + erroredChannel <- true + doneChannel <- true + break + } if done { doneChannel <- true break @@ -39,9 +48,10 @@ func channelWriterHandleBatch( recordsAndContexts *list.List, recordWriter IRecordWriter, writerOptions *cli.TWriterOptions, + erroredChannel chan<- bool, bufferedOutputStream *bufio.Writer, outputIsStdout bool, -) bool { +) (done bool, errored bool) { for e := recordsAndContexts.Front(); e != nil; e = e.Next() { recordAndContext := e.Value.(*types.RecordAndContext) @@ -56,6 +66,33 @@ func channelWriterHandleBatch( if !recordAndContext.EndOfStream { record := recordAndContext.Record + + // XXX more + // XXX also make sure this results in exit 1 & goroutine cleanup + if writerOptions.FatalOnErrorData { + ok := true + for pe := record.Head; pe != nil; pe = pe.Next { + if pe.Value.IsError() { + context := recordAndContext.Context + fmt.Fprintf(os.Stderr, "mlr: data error at NR=%d FNR=%d FILENAME=%s\n", + context.NR, context.FNR, context.FILENAME, + ) + is, err := pe.Value.GetError() + if is { + if err != nil { + fmt.Fprintf(os.Stderr, "mlr: field %s: %v\n", pe.Key, err) + } else { + fmt.Fprintf(os.Stderr, "mlr: field %s\n", pe.Key) + } + ok = false + } + } + } + if !ok { + return true, true + } + } + if record != nil { recordWriter.Write(record, bufferedOutputStream, outputIsStdout) } @@ -75,8 +112,8 @@ func channelWriterHandleBatch( // records before printing any, since it needs to compute max width // down columns. recordWriter.Write(nil, bufferedOutputStream, outputIsStdout) - return true + return true, false } } - return false + return false, false } diff --git a/internal/pkg/output/file_output_handlers.go b/internal/pkg/output/file_output_handlers.go index cd7c3f8968..c7cf6f4839 100644 --- a/internal/pkg/output/file_output_handlers.go +++ b/internal/pkg/output/file_output_handlers.go @@ -15,6 +15,7 @@ package output import ( "bufio" "container/list" + "errors" "fmt" "io" "os" @@ -213,10 +214,11 @@ type FileOutputHandler struct { // lazily created on WriteRecord. The record-writer / channel parts are // called only by WriteRecrod which is called by emit and tee variants; // print and dump variants call WriteString. - recordWriterOptions *cli.TWriterOptions - recordWriter IRecordWriter - recordOutputChannel chan *list.List // list of *types.RecordAndContext - recordDoneChannel chan bool + recordWriterOptions *cli.TWriterOptions + recordWriter IRecordWriter + recordOutputChannel chan *list.List // list of *types.RecordAndContext + recordDoneChannel chan bool + recordErroredChannel chan bool } func newOutputHandlerCommon( @@ -231,10 +233,11 @@ func newOutputHandlerCommon( bufferedOutputStream: bufio.NewWriter(handle), closeable: closeable, - recordWriterOptions: recordWriterOptions, - recordWriter: nil, - recordOutputChannel: nil, - recordDoneChannel: nil, + recordWriterOptions: recordWriterOptions, + recordWriter: nil, + recordOutputChannel: nil, + recordDoneChannel: nil, + recordErroredChannel: nil, } } @@ -368,12 +371,14 @@ func (handler *FileOutputHandler) setUpRecordWriter() error { handler.recordOutputChannel = make(chan *list.List, 1) // list of *types.RecordAndContext handler.recordDoneChannel = make(chan bool, 1) + handler.recordErroredChannel = make(chan bool, 1) go ChannelWriter( handler.recordOutputChannel, handler.recordWriter, handler.recordWriterOptions, handler.recordDoneChannel, + handler.recordErroredChannel, handler.bufferedOutputStream, false, // outputIsStdout ) @@ -382,7 +387,9 @@ func (handler *FileOutputHandler) setUpRecordWriter() error { } // ---------------------------------------------------------------- -func (handler *FileOutputHandler) Close() error { +func (handler *FileOutputHandler) Close() (retval error) { + retval = nil + if handler.recordOutputChannel != nil { // TODO: see if we need a real context emptyContext := types.Context{} @@ -392,6 +399,10 @@ func (handler *FileOutputHandler) Close() error { done := false for !done { select { + case _ = <-handler.recordErroredChannel: + done = true + retval = errors.New("exiting due to data error") // details already printed + break case _ = <-handler.recordDoneChannel: done = true break @@ -399,10 +410,14 @@ func (handler *FileOutputHandler) Close() error { } } + if retval != nil { + return retval + } + handler.bufferedOutputStream.Flush() if handler.closeable { return handler.handle.Close() - } else { + } else { // e.g. stdout return nil } } diff --git a/internal/pkg/stream/stream.go b/internal/pkg/stream/stream.go index 60be62a17d..933fb7d704 100644 --- a/internal/pkg/stream/stream.go +++ b/internal/pkg/stream/stream.go @@ -3,6 +3,7 @@ package stream import ( "bufio" "container/list" + "errors" "io" "github.com/johnkerl/miller/internal/pkg/cli" @@ -67,8 +68,9 @@ func Stream( // We're done when a fatal error is registered on input (file not found, // etc) or when the record-writer has written all its output. We use // channels to communicate both of these conditions. - errorChannel := make(chan error, 1) + inputErrorChannel := make(chan error, 1) doneWritingChannel := make(chan bool, 1) + erroredWritingChannel := make(chan bool, 1) // For mlr head, so a transformer can communicate it will disregard all // further input. It writes this back upstream, and that is passed back to @@ -81,17 +83,22 @@ func Stream( // error or end-of-processing happens. bufferedOutputStream := bufio.NewWriter(outputStream) - go recordReader.Read(fileNames, *initialContext, readerChannel, errorChannel, readerDownstreamDoneChannel) + go recordReader.Read(fileNames, *initialContext, readerChannel, inputErrorChannel, readerDownstreamDoneChannel) go transformers.ChainTransformer(readerChannel, readerDownstreamDoneChannel, recordTransformers, writerChannel, options) go output.ChannelWriter(writerChannel, recordWriter, &options.WriterOptions, doneWritingChannel, - bufferedOutputStream, outputIsStdout) + erroredWritingChannel, bufferedOutputStream, outputIsStdout) + var retval error done := false for !done { select { - case err := <-errorChannel: - return err + case ierr := <-inputErrorChannel: + retval = ierr + break + case _ = <-erroredWritingChannel: + retval = errors.New("exiting due to data error") // details already printed + break case _ = <-doneWritingChannel: done = true break @@ -100,5 +107,5 @@ func Stream( bufferedOutputStream.Flush() - return nil + return retval } From 98e61ff84331c8607ea539100760b23ec7fefbef Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sun, 27 Aug 2023 21:04:58 -0400 Subject: [PATCH 02/22] arithmetic.go error-reason propagation --- internal/pkg/bifs/arithmetic.go | 380 ++++++++++++++++++------------ internal/pkg/bifs/base.go | 29 +++ internal/pkg/mlrval/mlrval_new.go | 11 +- xtodo.txt | 5 + 4 files changed, 267 insertions(+), 158 deletions(-) create mode 100644 xtodo.txt diff --git a/internal/pkg/bifs/arithmetic.go b/internal/pkg/bifs/arithmetic.go index 871874e7e5..aded7bda4d 100644 --- a/internal/pkg/bifs/arithmetic.go +++ b/internal/pkg/bifs/arithmetic.go @@ -10,16 +10,20 @@ import ( // ================================================================ // Unary plus operator +func upos_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_unary("+", input1) +} + var upos_dispositions = [mlrval.MT_DIM]UnaryFunc{ /*INT */ _1u___, /*FLOAT */ _1u___, - /*BOOL */ _erro1, + /*BOOL */ upos_te, /*VOID */ _zero1, - /*STRING */ _erro1, + /*STRING */ upos_te, /*ARRAY */ _absn1, /*MAP */ _absn1, - /*FUNC */ _erro1, - /*ERROR */ _erro1, + /*FUNC */ upos_te, + /*ERROR */ upos_te, /*NULL */ _null1, /*ABSENT */ _absn1, } @@ -31,6 +35,10 @@ func BIF_plus_unary(input1 *mlrval.Mlrval) *mlrval.Mlrval { // ================================================================ // Unary minus operator +func uneg_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_unary("-", input1) +} + func uneg_i_i(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromInt(-input1.AcquireIntValue()) } @@ -42,13 +50,13 @@ func uneg_f_f(input1 *mlrval.Mlrval) *mlrval.Mlrval { var uneg_dispositions = [mlrval.MT_DIM]UnaryFunc{ /*INT */ uneg_i_i, /*FLOAT */ uneg_f_f, - /*BOOL */ _erro1, + /*BOOL */ uneg_te, /*VOID */ _zero1, - /*STRING */ _erro1, + /*STRING */ uneg_te, /*ARRAY */ _absn1, /*MAP */ _absn1, - /*FUNC */ _erro1, - /*ERROR */ _erro1, + /*FUNC */ uneg_te, + /*ERROR */ uneg_te, /*NULL */ _null1, /*ABSENT */ _absn1, } @@ -96,19 +104,23 @@ func plus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() + input2.AcquireFloatValue()) } +func plus_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("+", input1, input2) +} + var plus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ - // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {plus_n_ii, plus_f_if, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___}, - /*FLOAT */ {plus_f_fi, plus_f_ff, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_2___, _2___, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_2___, _2___, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _null, _absn}, - /*ABSENT */ {_2___, _2___, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT + /*INT */ {plus_n_ii, plus_f_if, plus_te, _1___, plus_te, _absn, _absn, plus_te, plus_te, _1___, _1___}, + /*FLOAT */ {plus_f_fi, plus_f_ff, plus_te, _1___, plus_te, _absn, _absn, plus_te, plus_te, _1___, _1___}, + /*BOOL */ {plus_te, plus_te, plus_te, plus_te, plus_te, _absn, _absn, plus_te, plus_te, plus_te, plus_te}, + /*VOID */ {_2___, _2___, plus_te, _void, plus_te, _absn, _absn, plus_te, plus_te, plus_te, _absn}, + /*STRING */ {plus_te, plus_te, plus_te, plus_te, plus_te, _absn, _absn, plus_te, plus_te, plus_te, plus_te}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, plus_te, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, plus_te, _absn, _absn, _absn}, + /*FUNC */ {plus_te, plus_te, plus_te, plus_te, plus_te, plus_te, plus_te, plus_te, plus_te, plus_te, plus_te}, + /*ERROR */ {plus_te, plus_te, plus_te, plus_te, plus_te, _absn, _absn, plus_te, plus_te, plus_te, plus_te}, + /*NULL */ {_2___, _2___, plus_te, plus_te, plus_te, _absn, _absn, plus_te, plus_te, _null, _absn}, + /*ABSENT */ {_2___, _2___, plus_te, _absn, plus_te, _absn, _absn, plus_te, plus_te, _absn, _absn}, } func BIF_plus_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -154,19 +166,23 @@ func minus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() - input2.AcquireFloatValue()) } +func minus_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("-", input1, input2) +} + var minus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {minus_n_ii, minus_f_if, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___}, - /*FLOAT */ {minus_f_fi, minus_f_ff, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_n2__, _n2__, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_2___, _2___, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _null, _absn}, - /*ABSENT */ {_2___, _2___, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {minus_n_ii, minus_f_if, minus_te, _1___, minus_te, _absn, _absn, minus_te, minus_te, _1___, _1___}, + /*FLOAT */ {minus_f_fi, minus_f_ff, minus_te, _1___, minus_te, _absn, _absn, minus_te, minus_te, _1___, _1___}, + /*BOOL */ {minus_te, minus_te, minus_te, minus_te, minus_te, _absn, _absn, minus_te, minus_te, minus_te, minus_te}, + /*VOID */ {_n2__, _n2__, minus_te, _void, minus_te, _absn, _absn, minus_te, minus_te, minus_te, _absn}, + /*STRING */ {minus_te, minus_te, minus_te, minus_te, minus_te, _absn, _absn, minus_te, minus_te, minus_te, minus_te}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, minus_te, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, minus_te, _absn, _absn, _absn}, + /*FUNC */ {minus_te, minus_te, minus_te, minus_te, minus_te, minus_te, minus_te, minus_te, minus_te, minus_te, minus_te}, + /*ERROR */ {minus_te, minus_te, minus_te, minus_te, minus_te, _absn, _absn, minus_te, minus_te, minus_te, minus_te}, + /*NULL */ {_2___, _2___, minus_te, minus_te, minus_te, _absn, _absn, minus_te, minus_te, _null, _absn}, + /*ABSENT */ {_2___, _2___, minus_te, _absn, minus_te, _absn, _absn, minus_te, minus_te, _absn, _absn}, } func BIF_minus_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -228,19 +244,23 @@ func times_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() * input2.AcquireFloatValue()) } +func times_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("*", input1, input2) +} + var times_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {times_n_ii, times_f_if, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___}, - /*FLOAT */ {times_f_fi, times_f_ff, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_2___, _2___, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_2___, _2___, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _null, _absn}, - /*ABSENT */ {_2___, _2___, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {times_n_ii, times_f_if, times_te, _1___, times_te, _absn, _absn, times_te, times_te, _1___, _1___}, + /*FLOAT */ {times_f_fi, times_f_ff, times_te, _1___, times_te, _absn, _absn, times_te, times_te, _1___, _1___}, + /*BOOL */ {times_te, times_te, times_te, times_te, times_te, _absn, _absn, times_te, times_te, times_te, times_te}, + /*VOID */ {_2___, _2___, times_te, _void, times_te, _absn, _absn, times_te, times_te, times_te, _absn}, + /*STRING */ {times_te, times_te, times_te, times_te, times_te, _absn, _absn, times_te, times_te, times_te, times_te}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, times_te, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, times_te, _absn, _absn, _absn}, + /*FUNC */ {times_te, times_te, times_te, times_te, times_te, times_te, times_te, times_te, times_te, times_te, times_te}, + /*ERROR */ {times_te, times_te, times_te, times_te, times_te, _absn, _absn, times_te, times_te, times_te, times_te}, + /*NULL */ {_2___, _2___, times_te, times_te, times_te, _absn, _absn, times_te, times_te, _null, _absn}, + /*ABSENT */ {_2___, _2___, times_te, _absn, times_te, _absn, _absn, times_te, times_te, _absn, _absn}, } func BIF_times(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -291,19 +311,23 @@ func divide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() / input2.AcquireFloatValue()) } +func divide_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("/", input1, input2) +} + var divide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {divide_n_ii, divide_f_if, _erro, _void, _erro, _absn, _absn, _erro, _erro, _1___, _1___}, - /*FLOAT */ {divide_f_fi, divide_f_ff, _erro, _void, _erro, _absn, _absn, _erro, _erro, _1___, _1___}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_i0__, _f0__, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_i0__, _f0__, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {divide_n_ii, divide_f_if, divide_te, _void, divide_te, _absn, _absn, divide_te, divide_te, _1___, _1___}, + /*FLOAT */ {divide_f_fi, divide_f_ff, divide_te, _void, divide_te, _absn, _absn, divide_te, divide_te, _1___, _1___}, + /*BOOL */ {divide_te, divide_te, divide_te, divide_te, divide_te, _absn, _absn, divide_te, divide_te, divide_te, divide_te}, + /*VOID */ {_void, _void, divide_te, _void, divide_te, _absn, _absn, divide_te, divide_te, divide_te, _absn}, + /*STRING */ {divide_te, divide_te, divide_te, divide_te, divide_te, _absn, _absn, divide_te, divide_te, divide_te, divide_te}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, divide_te, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, divide_te, _absn, _absn, _absn}, + /*FUNC */ {divide_te, divide_te, divide_te, divide_te, divide_te, divide_te, divide_te, divide_te, divide_te, divide_te, divide_te}, + /*ERROR */ {divide_te, divide_te, divide_te, divide_te, divide_te, _absn, _absn, divide_te, divide_te, divide_te, divide_te}, + /*NULL */ {_i0__, _f0__, divide_te, divide_te, divide_te, _absn, _absn, divide_te, divide_te, divide_te, _absn}, + /*ABSENT */ {_i0__, _f0__, divide_te, _absn, divide_te, _absn, _absn, divide_te, divide_te, _absn, _absn}, } func BIF_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -352,19 +376,23 @@ func int_divide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(math.Floor(input1.AcquireFloatValue() / input2.AcquireFloatValue())) } +func idivide_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("//", input1, input2) +} + var int_divide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {int_divide_n_ii, int_divide_f_if, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*FLOAT */ {int_divide_f_fi, int_divide_f_ff, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_i0__, _f0__, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {int_divide_n_ii, int_divide_f_if, idivide_te, _void, idivide_te, _absn, _absn, idivide_te, idivide_te, idivide_te, _1___}, + /*FLOAT */ {int_divide_f_fi, int_divide_f_ff, idivide_te, _void, idivide_te, _absn, _absn, idivide_te, idivide_te, idivide_te, _1___}, + /*BOOL */ {idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, _absn, _absn, idivide_te, idivide_te, idivide_te, idivide_te}, + /*VOID */ {_void, _void, idivide_te, _void, idivide_te, _absn, _absn, idivide_te, idivide_te, idivide_te, _absn}, + /*STRING */ {idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, _absn, _absn, idivide_te, idivide_te, idivide_te, idivide_te}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, idivide_te, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, idivide_te, _absn, _absn, _absn}, + /*FUNC */ {idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, idivide_te}, + /*ERROR */ {idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, _absn, _absn, idivide_te, idivide_te, idivide_te, idivide_te}, + /*NULL */ {idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, _absn, _absn, idivide_te, idivide_te, idivide_te, _absn}, + /*ABSENT */ {_i0__, _f0__, idivide_te, _absn, idivide_te, _absn, _absn, idivide_te, idivide_te, _absn, _absn}, } func BIF_int_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -388,19 +416,23 @@ func dotplus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() + input2.AcquireFloatValue()) } +func dotplus_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary(".+", input1, input2) +} + var dot_plus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {dotplus_i_ii, dotplus_f_if, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___}, - /*FLOAT */ {dotplus_f_fi, dotplus_f_ff, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_2___, _2___, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_2___, _2___, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _null, _absn}, - /*ABSENT */ {_2___, _2___, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {dotplus_i_ii, dotplus_f_if, dotplus_te, _1___, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, _1___, _1___}, + /*FLOAT */ {dotplus_f_fi, dotplus_f_ff, dotplus_te, _1___, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, _1___, _1___}, + /*BOOL */ {dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, dotplus_te, dotplus_te}, + /*VOID */ {_2___, _2___, dotplus_te, _void, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, dotplus_te, _absn}, + /*STRING */ {dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, dotplus_te, dotplus_te}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotplus_te, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotplus_te, _absn, _absn, _absn}, + /*FUNC */ {dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te}, + /*ERROR */ {dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, dotplus_te, dotplus_te}, + /*NULL */ {_2___, _2___, dotplus_te, dotplus_te, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, _null, _absn}, + /*ABSENT */ {_2___, _2___, dotplus_te, _absn, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, _absn, _absn}, } func BIF_dot_plus(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -424,19 +456,23 @@ func dotminus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() - input2.AcquireFloatValue()) } +func dotminus_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary(".-", input1, input2) +} + var dotminus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {dotminus_i_ii, dotminus_f_if, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___}, - /*FLOAT */ {dotminus_f_fi, dotminus_f_ff, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_n2__, _n2__, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_n2__, _n2__, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _null, _absn}, - /*ABSENT */ {_n2__, _n2__, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {dotminus_i_ii, dotminus_f_if, dotminus_te, _1___, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, _1___, _1___}, + /*FLOAT */ {dotminus_f_fi, dotminus_f_ff, dotminus_te, _1___, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, _1___, _1___}, + /*BOOL */ {dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, dotminus_te, dotminus_te}, + /*VOID */ {_n2__, _n2__, dotminus_te, _void, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, dotminus_te, _absn}, + /*STRING */ {dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, dotminus_te, dotminus_te}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotminus_te, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotminus_te, _absn, _absn, _absn}, + /*FUNC */ {dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te}, + /*ERROR */ {dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, dotminus_te, dotminus_te}, + /*NULL */ {_n2__, _n2__, dotminus_te, dotminus_te, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, _null, _absn}, + /*ABSENT */ {_n2__, _n2__, dotminus_te, _absn, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, _absn, _absn}, } func BIF_dot_minus(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -460,19 +496,23 @@ func dottimes_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() * input2.AcquireFloatValue()) } +func dottimes_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary(".*", input1, input2) +} + var dottimes_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {dottimes_i_ii, dottimes_f_if, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___}, - /*FLOAT */ {dottimes_f_fi, dottimes_f_ff, _erro, _1___, _erro, _absn, _absn, _erro, _erro, _1___, _1___}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_n2__, _n2__, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_2___, _2___, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_2___, _2___, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {dottimes_i_ii, dottimes_f_if, dottimes_te, _1___, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, _1___, _1___}, + /*FLOAT */ {dottimes_f_fi, dottimes_f_ff, dottimes_te, _1___, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, _1___, _1___}, + /*BOOL */ {dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, dottimes_te, dottimes_te}, + /*VOID */ {_n2__, _n2__, dottimes_te, _void, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, dottimes_te, _absn}, + /*STRING */ {dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, dottimes_te, dottimes_te}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dottimes_te, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dottimes_te, _absn, _absn, _absn}, + /*FUNC */ {dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te}, + /*ERROR */ {dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, dottimes_te, dottimes_te}, + /*NULL */ {_2___, _2___, dottimes_te, dottimes_te, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, dottimes_te, _absn}, + /*ABSENT */ {_2___, _2___, dottimes_te, _absn, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, _absn, _absn}, } func BIF_dot_times(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -496,19 +536,23 @@ func dotdivide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() / input2.AcquireFloatValue()) } +func dotdivide_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("./", input1, input2) +} + var dotdivide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {dotdivide_i_ii, dotdivide_f_if, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*FLOAT */ {dotdivide_f_fi, dotdivide_f_ff, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_2___, _2___, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {dotdivide_i_ii, dotdivide_f_if, dotdivide_te, _void, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, dotdivide_te, _1___}, + /*FLOAT */ {dotdivide_f_fi, dotdivide_f_ff, dotdivide_te, _void, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, dotdivide_te, _1___}, + /*BOOL */ {dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te}, + /*VOID */ {_void, _void, dotdivide_te, _void, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, dotdivide_te, _absn}, + /*STRING */ {dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotdivide_te, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotdivide_te, _absn, _absn, _absn}, + /*FUNC */ {dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te}, + /*ERROR */ {dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te}, + /*NULL */ {dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, dotdivide_te, _absn}, + /*ABSENT */ {_2___, _2___, dotdivide_te, _absn, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, _absn, _absn}, } func BIF_dot_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -557,19 +601,23 @@ func dotidivide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(math.Floor(input1.AcquireFloatValue() / input2.AcquireFloatValue())) } +func dotidivide_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary(".//", input1, input2) +} + var dotidivide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {dotidivide_i_ii, dotidivide_f_if, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*FLOAT */ {dotidivide_f_fi, dotidivide_f_ff, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_2___, _2___, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, + /*INT */ {dotidivide_i_ii, dotidivide_f_if, dotidivide_te, _void, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, _1___}, + /*FLOAT */ {dotidivide_f_fi, dotidivide_f_ff, dotidivide_te, _void, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, _1___}, + /*BOOL */ {dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te}, + /*VOID */ {_void, _void, dotidivide_te, _void, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, _absn}, + /*STRING */ {dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotidivide_te, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotidivide_te, _absn, _absn, _absn}, + /*FUNC */ {dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te}, + /*ERROR */ {dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te}, + /*NULL */ {dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, _absn}, + /*ABSENT */ {_2___, _2___, dotidivide_te, _absn, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, _absn}, } func BIF_dot_int_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -621,19 +669,23 @@ func modulus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(a - b*math.Floor(a/b)) } +func modulus_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("%", input1, input2) +} + var modulus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {modulus_i_ii, modulus_f_if, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*FLOAT */ {modulus_f_fi, modulus_f_ff, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_i0__, _f0__, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {modulus_i_ii, modulus_f_if, modulus_te, _void, modulus_te, _absn, _absn, modulus_te, modulus_te, modulus_te, _1___}, + /*FLOAT */ {modulus_f_fi, modulus_f_ff, modulus_te, _void, modulus_te, _absn, _absn, modulus_te, modulus_te, modulus_te, _1___}, + /*BOOL */ {modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, _absn, _absn, modulus_te, modulus_te, modulus_te, modulus_te}, + /*VOID */ {_void, _void, modulus_te, _void, modulus_te, _absn, _absn, modulus_te, modulus_te, modulus_te, _absn}, + /*STRING */ {modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, _absn, _absn, modulus_te, modulus_te, modulus_te, modulus_te}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, modulus_te, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, modulus_te, _absn, _absn, _absn}, + /*FUNC */ {modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, modulus_te}, + /*ERROR */ {modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, _absn, _absn, modulus_te, modulus_te, modulus_te, modulus_te}, + /*NULL */ {modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, _absn, _absn, modulus_te, modulus_te, modulus_te, _absn}, + /*ABSENT */ {_i0__, _f0__, modulus_te, _absn, modulus_te, _absn, _absn, modulus_te, modulus_te, _absn, _absn}, } func BIF_modulus(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -793,19 +845,23 @@ func min_s_ss(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } } +func min_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("min", input1, input2) +} + var min_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {min_i_ii, min_f_if, _1___, _1___, _1___, _absn, _absn, _erro, _erro, _1___, _1___}, - /*FLOAT */ {min_f_fi, min_f_ff, _1___, _1___, _1___, _absn, _absn, _erro, _erro, _1___, _1___}, - /*BOOL */ {_2___, _2___, min_b_bb, _1___, _1___, _absn, _absn, _erro, _erro, _1___, _1___}, - /*VOID */ {_2___, _2___, _2___, _void, _void, _absn, _absn, _erro, _erro, _1___, _1___}, - /*STRING */ {_2___, _2___, _2___, _void, min_s_ss, _absn, _absn, _erro, _erro, _1___, _1___}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_2___, _2___, _2___, _2___, _2___, _absn, _absn, _erro, _erro, _null, _null}, - /*ABSENT */ {_2___, _2___, _2___, _2___, _2___, _absn, _absn, _erro, _erro, _null, _absn}, + /*INT */ {min_i_ii, min_f_if, _1___, _1___, _1___, _absn, _absn, min_te, min_te, _1___, _1___}, + /*FLOAT */ {min_f_fi, min_f_ff, _1___, _1___, _1___, _absn, _absn, min_te, min_te, _1___, _1___}, + /*BOOL */ {_2___, _2___, min_b_bb, _1___, _1___, _absn, _absn, min_te, min_te, _1___, _1___}, + /*VOID */ {_2___, _2___, _2___, _void, _void, _absn, _absn, min_te, min_te, _1___, _1___}, + /*STRING */ {_2___, _2___, _2___, _void, min_s_ss, _absn, _absn, min_te, min_te, _1___, _1___}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, min_te, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, min_te, _absn, _absn, _absn}, + /*FUNC */ {min_te, min_te, min_te, min_te, min_te, min_te, min_te, min_te, min_te, min_te, min_te}, + /*ERROR */ {min_te, min_te, min_te, min_te, min_te, _absn, _absn, min_te, min_te, min_te, min_te}, + /*NULL */ {_2___, _2___, _2___, _2___, _2___, _absn, _absn, min_te, min_te, _null, _null}, + /*ABSENT */ {_2___, _2___, _2___, _2___, _2___, _absn, _absn, min_te, min_te, _null, _absn}, } // BIF_min_binary is not a direct DSL function. It's a helper here, @@ -853,6 +909,10 @@ func bif_min_unary_map(input1 *mlrval.Mlrval) *mlrval.Mlrval { // if this is defined statically. So, we use a "package init" function. var min_unary_dispositions = [mlrval.MT_DIM]UnaryFunc{} +func min_unary_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_unary("min", input1) +} + func init() { min_unary_dispositions = [mlrval.MT_DIM]UnaryFunc{ /*INT */ _1u___, @@ -862,8 +922,8 @@ func init() { /*STRING */ _1u___, /*ARRAY */ bif_min_unary_array, /*MAP */ bif_min_unary_map, - /*FUNC */ _erro1, - /*ERROR */ _erro1, + /*FUNC */ min_unary_te, + /*ERROR */ min_unary_te, /*NULL */ _null1, /*ABSENT */ _absn1, } @@ -955,19 +1015,23 @@ func max_s_ss(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } } +func max_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("max", input1, input2) +} + var max_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {max_i_ii, max_f_if, _2___, _2___, _2___, _absn, _absn, _erro, _erro, _null, _1___}, - /*FLOAT */ {max_f_fi, max_f_ff, _2___, _2___, _2___, _absn, _absn, _erro, _erro, _null, _1___}, - /*BOOL */ {_1___, _1___, max_b_bb, _2___, _2___, _absn, _absn, _erro, _erro, _null, _1___}, - /*VOID */ {_1___, _1___, _1___, _void, _2___, _absn, _absn, _erro, _erro, _null, _1___}, - /*STRING */ {_1___, _1___, _1___, _1___, max_s_ss, _absn, _absn, _erro, _erro, _null, _1___}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _null, _erro}, - /*NULL */ {_null, _null, _null, _null, _null, _absn, _absn, _erro, _null, _null, _absn}, - /*ABSENT */ {_2___, _2___, _2___, _2___, _2___, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {max_i_ii, max_f_if, _2___, _2___, _2___, _absn, _absn, max_te, max_te, _null, _1___}, + /*FLOAT */ {max_f_fi, max_f_ff, _2___, _2___, _2___, _absn, _absn, max_te, max_te, _null, _1___}, + /*BOOL */ {_1___, _1___, max_b_bb, _2___, _2___, _absn, _absn, max_te, max_te, _null, _1___}, + /*VOID */ {_1___, _1___, _1___, _void, _2___, _absn, _absn, max_te, max_te, _null, _1___}, + /*STRING */ {_1___, _1___, _1___, _1___, max_s_ss, _absn, _absn, max_te, max_te, _null, _1___}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, max_te, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, max_te, _absn, _absn, _absn}, + /*FUNC */ {max_te, max_te, max_te, max_te, max_te, max_te, max_te, max_te, max_te, max_te, max_te}, + /*ERROR */ {max_te, max_te, max_te, max_te, max_te, _absn, _absn, max_te, max_te, _null, max_te}, + /*NULL */ {_null, _null, _null, _null, _null, _absn, _absn, max_te, _null, _null, _absn}, + /*ABSENT */ {_2___, _2___, _2___, _2___, _2___, _absn, _absn, max_te, max_te, _absn, _absn}, } // BIF_max_binary is not a direct DSL function. It's a helper here, @@ -1015,6 +1079,10 @@ func bif_max_unary_map(input1 *mlrval.Mlrval) *mlrval.Mlrval { // if this is defined statically. So, we use a "package init" function. var max_unary_dispositions = [mlrval.MT_DIM]UnaryFunc{} +func max_unary_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_unary("max", input1) +} + func init() { max_unary_dispositions = [mlrval.MT_DIM]UnaryFunc{ /*INT */ _1u___, @@ -1024,8 +1092,8 @@ func init() { /*STRING */ _1u___, /*ARRAY */ bif_max_unary_array, /*MAP */ bif_max_unary_map, - /*FUNC */ _erro1, - /*ERROR */ _erro1, + /*FUNC */ max_unary_te, + /*ERROR */ max_unary_te, /*NULL */ _null1, /*ABSENT */ _absn1, } diff --git a/internal/pkg/bifs/base.go b/internal/pkg/bifs/base.go index 36aeb63d28..4ae9326512 100644 --- a/internal/pkg/bifs/base.go +++ b/internal/pkg/bifs/base.go @@ -48,6 +48,8 @@ package bifs import ( + "fmt" + "github.com/johnkerl/miller/internal/pkg/lib" "github.com/johnkerl/miller/internal/pkg/mlrval" "github.com/johnkerl/miller/internal/pkg/types" @@ -90,6 +92,19 @@ type ComparatorFunc func(*mlrval.Mlrval, *mlrval.Mlrval) int // and all the same length, so that the disposition matrices will look // reasonable rectangular even after gofmt has been run. +// ---------------------------------------------------------------- +// Type error for unary functions +func _type_error_unary(funcname string, input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mlrval.FromError( + fmt.Errorf( + "%s: unacceptable type (%s) with value (%s)", + funcname, + input1.GetTypeName(), + input1.String(), + ), + ) +} + // ---------------------------------------------------------------- // Return error (unary) func _erro1(input1 *mlrval.Mlrval) *mlrval.Mlrval { @@ -127,6 +142,20 @@ func _1u___(input1 *mlrval.Mlrval) *mlrval.Mlrval { } // ---------------------------------------------------------------- +// Type error for binary functions +func _type_error_binary(funcname string, input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return mlrval.FromError( + fmt.Errorf( + "%s: unacceptable types (%s, %s) with values (%s, %s)", + funcname, + input1.GetTypeName(), + input2.GetTypeName(), + input1.String(), + input2.String(), + ), + ) +} + // Return error (binary) func _erro(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.ERROR diff --git a/internal/pkg/mlrval/mlrval_new.go b/internal/pkg/mlrval/mlrval_new.go index a46bc73a07..c92152ec4d 100644 --- a/internal/pkg/mlrval/mlrval_new.go +++ b/internal/pkg/mlrval/mlrval_new.go @@ -5,8 +5,6 @@ package mlrval import ( - //"errors" - "github.com/johnkerl/miller/internal/pkg/lib" ) @@ -31,6 +29,15 @@ func FromDeferredType(input string) *Mlrval { } } +func FromError(err error) *Mlrval { + return &Mlrval{ + mvtype: MT_ERROR, + err: err, + printrep: ERROR_PRINTREP, + printrepValid: true, + } +} + // TODO: comment non-JIT context like mlr put -s. // TODO: comment re inferBool. func FromInferredType(input string) *Mlrval { diff --git a/xtodo.txt b/xtodo.txt new file mode 100644 index 0000000000..35e0a85dcd --- /dev/null +++ b/xtodo.txt @@ -0,0 +1,5 @@ +* _erro and _erro1 rid entirely of +* other modules obv ... long and winding road ... +* optional env var: MLR_DATA_ERROR_FAIL_FAST or somesuch +* maybe call it data-processing error to differentiate from input-data error -- ? +* look at: mr -vvv test/cases/io-spec-tsv/0004/cmd From 940dd644bfbda951ecbb9061d11ef63a51bad664 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Mon, 28 Aug 2023 21:27:38 -0400 Subject: [PATCH 03/22] more --- internal/pkg/bifs/strings.go | 52 +++++++++++++++++------------- internal/pkg/terminals/repl/dsl.go | 7 ++++ 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/internal/pkg/bifs/strings.go b/internal/pkg/bifs/strings.go index 6e1c76511a..53c3d32bce 100644 --- a/internal/pkg/bifs/strings.go +++ b/internal/pkg/bifs/strings.go @@ -42,19 +42,23 @@ func dot_s_xx(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromString(input1.String() + input2.String()) } +func dot_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary(".", input1, input2) +} + var dot_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {dot_s_xx, dot_s_xx, dot_s_xx, _s1__, dot_s_xx, _erro, _erro, _erro, _erro, _1___, _s1__}, - /*FLOAT */ {dot_s_xx, dot_s_xx, dot_s_xx, _s1__, dot_s_xx, _erro, _erro, _erro, _erro, _1___, _s1__}, - /*BOOL */ {dot_s_xx, dot_s_xx, dot_s_xx, _s1__, dot_s_xx, _erro, _erro, _erro, _erro, _1___, _s1__}, - /*VOID */ {_s2__, _s2__, _s2__, _void, _2___, _absn, _absn, _erro, _erro, _void, _void}, - /*STRING */ {dot_s_xx, dot_s_xx, dot_s_xx, _1___, dot_s_xx, _erro, _erro, _erro, _erro, _1___, _1___}, - /*ARRAY */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*MAP */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_s2__, _s2__, _s2__, _void, _2___, _absn, _absn, _erro, _erro, _null, _null}, - /*ABSENT */ {_s2__, _s2__, _s2__, _void, _2___, _absn, _absn, _erro, _erro, _null, _absn}, + /*INT */ {dot_s_xx, dot_s_xx, dot_s_xx, _s1__, dot_s_xx, dot_te, dot_te, dot_te, dot_te, _1___, _s1__}, + /*FLOAT */ {dot_s_xx, dot_s_xx, dot_s_xx, _s1__, dot_s_xx, dot_te, dot_te, dot_te, dot_te, _1___, _s1__}, + /*BOOL */ {dot_s_xx, dot_s_xx, dot_s_xx, _s1__, dot_s_xx, dot_te, dot_te, dot_te, dot_te, _1___, _s1__}, + /*VOID */ {_s2__, _s2__, _s2__, _void, _2___, _absn, _absn, dot_te, dot_te, _void, _void}, + /*STRING */ {dot_s_xx, dot_s_xx, dot_s_xx, _1___, dot_s_xx, dot_te, dot_te, dot_te, dot_te, _1___, _1___}, + /*ARRAY */ {dot_te, dot_te, dot_te, dot_te, dot_te, dot_te, dot_te, dot_te, dot_te, dot_te, dot_te}, + /*MAP */ {dot_te, dot_te, dot_te, dot_te, dot_te, dot_te, dot_te, dot_te, dot_te, dot_te, dot_te}, + /*FUNC */ {dot_te, dot_te, dot_te, dot_te, dot_te, dot_te, dot_te, dot_te, dot_te, dot_te, dot_te}, + /*ERROR */ {dot_te, dot_te, dot_te, dot_te, dot_te, _absn, _absn, dot_te, dot_te, dot_te, dot_te}, + /*NULL */ {_s2__, _s2__, _s2__, _void, _2___, _absn, _absn, dot_te, dot_te, _null, _null}, + /*ABSENT */ {_s2__, _s2__, _s2__, _void, _2___, _absn, _absn, dot_te, dot_te, _null, _absn}, } func BIF_dot(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -505,19 +509,23 @@ func fmtnum_bs(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return formatter.Format(intMv) } +func fmtnum_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("fmtnum", input1, input2) +} + var fmtnum_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {_erro, _erro, _erro, _erro, fmtnum_is, _erro, _erro, _erro, _erro, _erro, _absn}, - /*FLOAT */ {_erro, _erro, _erro, _erro, fmtnum_fs, _erro, _erro, _erro, _erro, _erro, _absn}, - /*BOOL */ {_erro, _erro, _erro, _erro, fmtnum_bs, _erro, _erro, _erro, _erro, _erro, _absn}, - /*VOID */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _absn}, - /*ARRAY */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _absn}, - /*MAP */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*NULL */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_absn, _absn, _erro, _absn, _absn, _erro, _erro, _erro, _erro, _absn, _absn}, + /*INT */ {fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_is, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, _absn}, + /*FLOAT */ {fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_fs, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, _absn}, + /*BOOL */ {fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_bs, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, _absn}, + /*VOID */ {fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, _absn}, + /*STRING */ {fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, _absn}, + /*ARRAY */ {fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, _absn}, + /*MAP */ {fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, _absn}, + /*FUNC */ {fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te}, + /*ERROR */ {fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te}, + /*NULL */ {fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, _absn}, + /*ABSENT */ {_absn, _absn, fmtnum_te, _absn, _absn, fmtnum_te, fmtnum_te, fmtnum_te, fmtnum_te, _absn, _absn}, } func BIF_fmtnum(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { diff --git a/internal/pkg/terminals/repl/dsl.go b/internal/pkg/terminals/repl/dsl.go index a499966fc8..87d6500f07 100644 --- a/internal/pkg/terminals/repl/dsl.go +++ b/internal/pkg/terminals/repl/dsl.go @@ -89,6 +89,13 @@ func (repl *Repl) handleDSLStringAux( filterExpression := repl.runtimeState.FilterExpression if filterExpression.IsNull() { // nothing to print + } else if filterExpression.IsError() { + _, err := filterExpression.GetError() + if err == nil { // No supporting information + fmt.Printf("\"%s\"\n", filterExpression.String()) + } else { + fmt.Printf("%v\n", err) + } } else if filterExpression.IsStringOrVoid() { fmt.Printf("\"%s\"\n", filterExpression.String()) } else { From 1dc3462af973e4fd2ff7d79318eabdac5131c680 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Mon, 28 Aug 2023 21:32:37 -0400 Subject: [PATCH 04/22] more --- internal/pkg/bifs/bits.go | 184 ++++++++++++++++++++++---------------- 1 file changed, 108 insertions(+), 76 deletions(-) diff --git a/internal/pkg/bifs/bits.go b/internal/pkg/bifs/bits.go index e309f7b4e7..e10d6e9b3e 100644 --- a/internal/pkg/bifs/bits.go +++ b/internal/pkg/bifs/bits.go @@ -11,16 +11,20 @@ func bitwise_not_i_i(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromInt(^input1.AcquireIntValue()) } +func bitwise_not_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_unary("~", input1) +} + var bitwise_not_dispositions = [mlrval.MT_DIM]UnaryFunc{ /*INT */ bitwise_not_i_i, - /*FLOAT */ _erro1, - /*BOOL */ _erro1, + /*FLOAT */ bitwise_not_te, + /*BOOL */ bitwise_not_te, /*VOID */ _void1, - /*STRING */ _erro1, + /*STRING */ bitwise_not_te, /*ARRAY */ _absn1, /*MAP */ _absn1, - /*FUNC */ _erro1, - /*ERROR */ _erro1, + /*FUNC */ bitwise_not_te, + /*ERROR */ bitwise_not_te, /*NULL */ _null1, /*ABSENT */ _absn1, } @@ -51,16 +55,20 @@ func bitcount_i_i(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromInt(int64(a)) } +func bitcount_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_unary("bitcount", input1) +} + var bitcount_dispositions = [mlrval.MT_DIM]UnaryFunc{ /*INT */ bitcount_i_i, - /*FLOAT */ _erro1, - /*BOOL */ _erro1, + /*FLOAT */ bitcount_te, + /*BOOL */ bitcount_te, /*VOID */ _void1, - /*STRING */ _erro1, + /*STRING */ bitcount_te, /*ARRAY */ _absn1, /*MAP */ _absn1, - /*FUNC */ _erro1, - /*ERROR */ _erro1, + /*FUNC */ bitcount_te, + /*ERROR */ bitcount_te, /*NULL */ _zero1, /*ABSENT */ _absn1, } @@ -76,19 +84,23 @@ func bitwise_and_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromInt(input1.AcquireIntValue() & input2.AcquireIntValue()) } +func bwandte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("&", input1, input2) +} + var bitwise_and_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {bitwise_and_i_ii, _erro, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*FLOAT */ {_erro, _erro, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_2___, _erro, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {bitwise_and_i_ii, bwandte, bwandte, _void, bwandte, _absn, _absn, bwandte, bwandte, bwandte, _1___}, + /*FLOAT */ {bwandte, bwandte, bwandte, _void, bwandte, _absn, _absn, bwandte, bwandte, bwandte, bwandte}, + /*BOOL */ {bwandte, bwandte, bwandte, bwandte, bwandte, _absn, _absn, bwandte, bwandte, bwandte, bwandte}, + /*VOID */ {_void, _void, bwandte, _void, bwandte, _absn, _absn, bwandte, bwandte, bwandte, _absn}, + /*STRING */ {bwandte, bwandte, bwandte, bwandte, bwandte, _absn, _absn, bwandte, bwandte, bwandte, bwandte}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, bwandte, _absn, bwandte, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, bwandte, _absn, bwandte, _absn}, + /*FUNC */ {bwandte, bwandte, bwandte, bwandte, bwandte, bwandte, bwandte, bwandte, bwandte, bwandte, bwandte}, + /*ERROR */ {bwandte, bwandte, bwandte, bwandte, bwandte, _absn, _absn, bwandte, bwandte, bwandte, bwandte}, + /*NULL */ {bwandte, bwandte, bwandte, bwandte, bwandte, bwandte, bwandte, bwandte, bwandte, bwandte, _absn}, + /*ABSENT */ {_2___, bwandte, bwandte, _absn, bwandte, _absn, _absn, bwandte, bwandte, _absn, _absn}, } func BIF_bitwise_and(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -102,19 +114,23 @@ func bitwise_or_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromInt(input1.AcquireIntValue() | input2.AcquireIntValue()) } +func bworte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("|", input1, input2) +} + var bitwise_or_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {bitwise_or_i_ii, _erro, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*FLOAT */ {_erro, _erro, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_2___, _erro, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {bitwise_or_i_ii, bworte, bworte, _void, bworte, _absn, _absn, bworte, bworte, bworte, _1___}, + /*FLOAT */ {bworte, bworte, bworte, _void, bworte, _absn, _absn, bworte, bworte, bworte, bworte}, + /*BOOL */ {bworte, bworte, bworte, bworte, bworte, _absn, _absn, bworte, bworte, bworte, bworte}, + /*VOID */ {_void, _void, bworte, _void, bworte, _absn, _absn, bworte, bworte, bworte, _absn}, + /*STRING */ {bworte, bworte, bworte, bworte, bworte, _absn, _absn, bworte, bworte, bworte, bworte}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, bworte, _absn, bworte, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, bworte, _absn, bworte, _absn}, + /*FUNC */ {bworte, bworte, bworte, bworte, bworte, bworte, bworte, bworte, bworte, bworte, bworte}, + /*ERROR */ {bworte, bworte, bworte, bworte, bworte, _absn, _absn, bworte, bworte, bworte, bworte}, + /*NULL */ {bworte, bworte, bworte, bworte, bworte, bworte, bworte, bworte, bworte, bworte, _absn}, + /*ABSENT */ {_2___, bworte, bworte, _absn, bworte, _absn, _absn, bworte, bworte, _absn, _absn}, } func BIF_bitwise_or(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -128,19 +144,23 @@ func bitwise_xor_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromInt(input1.AcquireIntValue() ^ input2.AcquireIntValue()) } +func bwxorte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("^", input1, input2) +} + var bitwise_xor_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {bitwise_xor_i_ii, _erro, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*FLOAT */ {_erro, _erro, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_2___, _erro, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {bitwise_xor_i_ii, bwxorte, bwxorte, _void, bwxorte, _absn, _absn, bwxorte, bwxorte, bwxorte, _1___}, + /*FLOAT */ {bwxorte, bwxorte, bwxorte, _void, bwxorte, _absn, _absn, bwxorte, bwxorte, bwxorte, bwxorte}, + /*BOOL */ {bwxorte, bwxorte, bwxorte, bwxorte, bwxorte, _absn, _absn, bwxorte, bwxorte, bwxorte, bwxorte}, + /*VOID */ {_void, _void, bwxorte, _void, bwxorte, _absn, _absn, bwxorte, bwxorte, bwxorte, _absn}, + /*STRING */ {bwxorte, bwxorte, bwxorte, bwxorte, bwxorte, _absn, _absn, bwxorte, bwxorte, bwxorte, bwxorte}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, bwxorte, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, bwxorte, _absn, _absn, _absn}, + /*FUNC */ {bwxorte, bwxorte, bwxorte, bwxorte, bwxorte, bwxorte, bwxorte, bwxorte, bwxorte, bwxorte, bwxorte}, + /*ERROR */ {bwxorte, bwxorte, bwxorte, bwxorte, bwxorte, _absn, _absn, bwxorte, bwxorte, bwxorte, bwxorte}, + /*NULL */ {bwxorte, bwxorte, bwxorte, bwxorte, bwxorte, bwxorte, bwxorte, bwxorte, bwxorte, bwxorte, _absn}, + /*ABSENT */ {_2___, bwxorte, bwxorte, _absn, bwxorte, _absn, _absn, bwxorte, bwxorte, _absn, _absn}, } func BIF_bitwise_xor(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -154,19 +174,23 @@ func lsh_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromInt(input1.AcquireIntValue() << uint64(input2.AcquireIntValue())) } +func lshfte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("<<", input1, input2) +} + var left_shift_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {lsh_i_ii, _erro, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*FLOAT */ {_erro, _erro, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_2___, _erro, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {lsh_i_ii, lshfte, lshfte, _void, lshfte, _absn, _absn, lshfte, lshfte, lshfte, _1___}, + /*FLOAT */ {lshfte, lshfte, lshfte, _void, lshfte, _absn, _absn, lshfte, lshfte, lshfte, lshfte}, + /*BOOL */ {lshfte, lshfte, lshfte, lshfte, lshfte, _absn, _absn, lshfte, lshfte, lshfte, lshfte}, + /*VOID */ {_void, _void, lshfte, _void, lshfte, _absn, _absn, lshfte, lshfte, lshfte, _absn}, + /*STRING */ {lshfte, lshfte, lshfte, lshfte, lshfte, _absn, _absn, lshfte, lshfte, lshfte, lshfte}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, lshfte, _absn, lshfte, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, lshfte, _absn, lshfte, _absn}, + /*FUNC */ {lshfte, lshfte, lshfte, lshfte, lshfte, lshfte, lshfte, lshfte, lshfte, lshfte, lshfte}, + /*ERROR */ {lshfte, lshfte, lshfte, lshfte, lshfte, _absn, _absn, lshfte, lshfte, lshfte, lshfte}, + /*NULL */ {lshfte, lshfte, lshfte, lshfte, lshfte, lshfte, lshfte, lshfte, lshfte, lshfte, _absn}, + /*ABSENT */ {_2___, lshfte, lshfte, _absn, lshfte, _absn, _absn, lshfte, lshfte, _absn, _absn}, } func BIF_left_shift(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -180,19 +204,23 @@ func srsh_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromInt(input1.AcquireIntValue() >> uint64(input2.AcquireIntValue())) } +func srste(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary(">>>", input1, input2) +} + var signed_right_shift_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {srsh_i_ii, _erro, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*FLOAT */ {_erro, _erro, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_2___, _erro, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {srsh_i_ii, srste, srste, _void, srste, _absn, _absn, srste, srste, srste, _1___}, + /*FLOAT */ {srste, srste, srste, _void, srste, _absn, _absn, srste, srste, srste, srste}, + /*BOOL */ {srste, srste, srste, srste, srste, _absn, _absn, srste, srste, srste, srste}, + /*VOID */ {_void, _void, srste, _void, srste, _absn, _absn, srste, srste, srste, _absn}, + /*STRING */ {srste, srste, srste, srste, srste, _absn, _absn, srste, srste, srste, srste}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, srste, _absn, srste, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, srste, _absn, srste, _absn}, + /*FUNC */ {srste, srste, srste, srste, srste, srste, srste, srste, srste, srste, srste}, + /*ERROR */ {srste, srste, srste, srste, srste, _absn, _absn, srste, srste, srste, srste}, + /*NULL */ {srste, srste, srste, srste, srste, srste, srste, srste, srste, srste, _absn}, + /*ABSENT */ {_2___, srste, srste, _absn, srste, _absn, _absn, srste, srste, _absn, _absn}, } func BIF_signed_right_shift(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -209,19 +237,23 @@ func ursh_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromInt(int64(uc)) } +func rste(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary(">>", input1, input2) +} + var unsigned_right_shift_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {ursh_i_ii, _erro, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*FLOAT */ {_erro, _erro, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_2___, _erro, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {ursh_i_ii, rste, rste, _void, rste, _absn, _absn, rste, rste, rste, _1___}, + /*FLOAT */ {rste, rste, rste, _void, rste, _absn, _absn, rste, rste, rste, rste}, + /*BOOL */ {rste, rste, rste, rste, rste, _absn, _absn, rste, rste, rste, rste}, + /*VOID */ {_void, _void, rste, _void, rste, _absn, _absn, rste, rste, rste, _absn}, + /*STRING */ {rste, rste, rste, rste, rste, _absn, _absn, rste, rste, rste, rste}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, rste, _absn, rste, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, rste, _absn, rste, _absn}, + /*FUNC */ {rste, rste, rste, rste, rste, rste, rste, rste, rste, rste, rste}, + /*ERROR */ {rste, rste, rste, rste, rste, _absn, _absn, rste, rste, rste, rste}, + /*NULL */ {rste, rste, rste, rste, rste, rste, rste, rste, rste, rste, _absn}, + /*ABSENT */ {_2___, rste, rste, _absn, rste, _absn, _absn, rste, rste, _absn, _absn}, } func BIF_unsigned_right_shift(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { From 133ce6defe104ad44505f0d279dcd9718351aa7a Mon Sep 17 00:00:00 2001 From: John Kerl Date: Mon, 28 Aug 2023 23:21:59 -0400 Subject: [PATCH 05/22] more --- internal/pkg/bifs/cmp.go | 182 ++++++++++++++++++++++----------------- 1 file changed, 105 insertions(+), 77 deletions(-) diff --git a/internal/pkg/bifs/cmp.go b/internal/pkg/bifs/cmp.go index ede4170559..a98470cd36 100644 --- a/internal/pkg/bifs/cmp.go +++ b/internal/pkg/bifs/cmp.go @@ -270,111 +270,139 @@ func ne_b_mm(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { // if this is defined statically. So, we use a "package init" function. var eq_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{} +func eqte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("==", input1, input2) +} + func init() { eq_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {eq_b_ii, eq_b_if, _fals, eq_b_xs, eq_b_xs, _fals, _fals, _erro, _erro, _fals, _absn}, - /*FLOAT */ {eq_b_fi, eq_b_ff, _fals, eq_b_xs, eq_b_xs, _fals, _fals, _erro, _erro, _fals, _absn}, - /*BOOL */ {_fals, _fals, eq_b_bb, _fals, _fals, _fals, _fals, _erro, _erro, _fals, _absn}, - /*VOID */ {eq_b_sx, eq_b_sx, _fals, eq_b_ss, eq_b_ss, _fals, _fals, _erro, _erro, _fals, _absn}, - /*STRING */ {eq_b_sx, eq_b_sx, _fals, eq_b_ss, eq_b_ss, _fals, _fals, _erro, _erro, _fals, _absn}, - /*ARRAY */ {_fals, _fals, _fals, _fals, _fals, eq_b_aa, _fals, _erro, _erro, _fals, _absn}, - /*MAP */ {_fals, _fals, _fals, _fals, _fals, _fals, eq_b_mm, _erro, _erro, _fals, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*NULL */ {_fals, _fals, _fals, _fals, _fals, _fals, _fals, _erro, _erro, _true, _absn}, - /*ABSENT */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {eq_b_ii, eq_b_if, _fals, eq_b_xs, eq_b_xs, _fals, _fals, eqte, eqte, _fals, _absn}, + /*FLOAT */ {eq_b_fi, eq_b_ff, _fals, eq_b_xs, eq_b_xs, _fals, _fals, eqte, eqte, _fals, _absn}, + /*BOOL */ {_fals, _fals, eq_b_bb, _fals, _fals, _fals, _fals, eqte, eqte, _fals, _absn}, + /*VOID */ {eq_b_sx, eq_b_sx, _fals, eq_b_ss, eq_b_ss, _fals, _fals, eqte, eqte, _fals, _absn}, + /*STRING */ {eq_b_sx, eq_b_sx, _fals, eq_b_ss, eq_b_ss, _fals, _fals, eqte, eqte, _fals, _absn}, + /*ARRAY */ {_fals, _fals, _fals, _fals, _fals, eq_b_aa, _fals, eqte, eqte, _fals, _absn}, + /*MAP */ {_fals, _fals, _fals, _fals, _fals, _fals, eq_b_mm, eqte, eqte, _fals, _absn}, + /*FUNC */ {eqte, eqte, eqte, eqte, eqte, eqte, eqte, eqte, eqte, eqte, eqte}, + /*ERROR */ {eqte, eqte, eqte, eqte, eqte, eqte, eqte, eqte, eqte, eqte, eqte}, + /*NULL */ {_fals, _fals, _fals, _fals, _fals, _fals, _fals, eqte, eqte, _true, _absn}, + /*ABSENT */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, eqte, eqte, _absn, _absn}, } } +func nete(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("!=", input1, input2) +} + var ne_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {ne_b_ii, ne_b_if, _true, ne_b_xs, ne_b_xs, _true, _true, _erro, _erro, _true, _absn}, - /*FLOAT */ {ne_b_fi, ne_b_ff, _true, ne_b_xs, ne_b_xs, _true, _true, _erro, _erro, _true, _absn}, - /*BOOL */ {_true, _true, ne_b_bb, _true, _true, _true, _true, _erro, _erro, _true, _absn}, - /*VOID */ {ne_b_sx, ne_b_sx, _true, ne_b_ss, ne_b_ss, _true, _true, _erro, _erro, _true, _absn}, - /*STRING */ {ne_b_sx, ne_b_sx, _true, ne_b_ss, ne_b_ss, _true, _true, _erro, _erro, _true, _absn}, - /*ARRAY */ {_true, _true, _true, _true, _true, ne_b_aa, _true, _erro, _erro, _true, _absn}, - /*MAP */ {_true, _true, _true, _true, _true, _true, ne_b_mm, _erro, _erro, _true, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*NULL */ {_true, _true, _true, _true, _true, _true, _true, _erro, _erro, _fals, _absn}, - /*ABSENT */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _erro, _absn, _absn}, + /*INT */ {ne_b_ii, ne_b_if, _true, ne_b_xs, ne_b_xs, _true, _true, nete, nete, _true, _absn}, + /*FLOAT */ {ne_b_fi, ne_b_ff, _true, ne_b_xs, ne_b_xs, _true, _true, nete, nete, _true, _absn}, + /*BOOL */ {_true, _true, ne_b_bb, _true, _true, _true, _true, nete, nete, _true, _absn}, + /*VOID */ {ne_b_sx, ne_b_sx, _true, ne_b_ss, ne_b_ss, _true, _true, nete, nete, _true, _absn}, + /*STRING */ {ne_b_sx, ne_b_sx, _true, ne_b_ss, ne_b_ss, _true, _true, nete, nete, _true, _absn}, + /*ARRAY */ {_true, _true, _true, _true, _true, ne_b_aa, _true, nete, nete, _true, _absn}, + /*MAP */ {_true, _true, _true, _true, _true, _true, ne_b_mm, nete, nete, _true, _absn}, + /*FUNC */ {nete, nete, nete, nete, nete, nete, nete, nete, nete, nete, nete}, + /*ERROR */ {nete, nete, nete, nete, nete, nete, nete, nete, nete, nete, nete}, + /*NULL */ {_true, _true, _true, _true, _true, _true, _true, nete, nete, _fals, _absn}, + /*ABSENT */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, nete, nete, _absn, _absn}, +} + +func gtte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary(">", input1, input2) } var gt_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {gt_b_ii, gt_b_if, _fals, gt_b_xs, gt_b_xs, _fals, _fals, _erro, _erro, _fals, _absn}, - /*FLOAT */ {gt_b_fi, gt_b_ff, _fals, gt_b_xs, gt_b_xs, _fals, _fals, _erro, _erro, _fals, _absn}, - /*BOOL */ {_fals, _fals, gt_b_bb, _fals, _fals, _fals, _fals, _erro, _erro, _fals, _absn}, - /*VOID */ {gt_b_sx, gt_b_sx, _fals, gt_b_ss, gt_b_ss, _fals, _fals, _erro, _erro, _fals, _absn}, - /*STRING */ {gt_b_sx, gt_b_sx, _fals, gt_b_ss, gt_b_ss, _fals, _fals, _erro, _erro, _fals, _absn}, - /*ARRAY */ {_fals, _fals, _fals, _fals, _fals, _erro, _fals, _erro, _erro, _fals, _absn}, - /*MAP */ {_fals, _fals, _fals, _fals, _fals, _fals, _erro, _erro, _erro, _fals, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _fals, _erro}, - /*NULL */ {_true, _true, _true, _true, _true, _absn, _absn, _erro, _true, _fals, _fals}, - /*ABSENT */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _erro, _true, _absn}, + /*INT */ {gt_b_ii, gt_b_if, _fals, gt_b_xs, gt_b_xs, _fals, _fals, gtte, gtte, _fals, _absn}, + /*FLOAT */ {gt_b_fi, gt_b_ff, _fals, gt_b_xs, gt_b_xs, _fals, _fals, gtte, gtte, _fals, _absn}, + /*BOOL */ {_fals, _fals, gt_b_bb, _fals, _fals, _fals, _fals, gtte, gtte, _fals, _absn}, + /*VOID */ {gt_b_sx, gt_b_sx, _fals, gt_b_ss, gt_b_ss, _fals, _fals, gtte, gtte, _fals, _absn}, + /*STRING */ {gt_b_sx, gt_b_sx, _fals, gt_b_ss, gt_b_ss, _fals, _fals, gtte, gtte, _fals, _absn}, + /*ARRAY */ {_fals, _fals, _fals, _fals, _fals, gtte, _fals, gtte, gtte, _fals, _absn}, + /*MAP */ {_fals, _fals, _fals, _fals, _fals, _fals, gtte, gtte, gtte, _fals, _absn}, + /*FUNC */ {gtte, gtte, gtte, gtte, gtte, gtte, gtte, gtte, gtte, gtte, gtte}, + /*ERROR */ {gtte, gtte, gtte, gtte, gtte, gtte, gtte, gtte, gtte, _fals, gtte}, + /*NULL */ {_true, _true, _true, _true, _true, _absn, _absn, gtte, _true, _fals, _fals}, + /*ABSENT */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, gtte, gtte, _true, _absn}, +} + +func gete(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary(">=", input1, input2) } var ge_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {ge_b_ii, ge_b_if, _fals, ge_b_xs, ge_b_xs, _fals, _fals, _erro, _erro, _fals, _absn}, - /*FLOAT */ {ge_b_fi, ge_b_ff, _fals, ge_b_xs, ge_b_xs, _fals, _fals, _erro, _erro, _fals, _absn}, - /*BOOL */ {_fals, _fals, ge_b_bb, _fals, _fals, _fals, _fals, _erro, _erro, _fals, _absn}, - /*VOID */ {ge_b_sx, ge_b_sx, _fals, ge_b_ss, ge_b_ss, _fals, _fals, _erro, _erro, _fals, _absn}, - /*STRING */ {ge_b_sx, ge_b_sx, _fals, ge_b_ss, ge_b_ss, _fals, _fals, _erro, _erro, _fals, _absn}, - /*ARRAY */ {_fals, _fals, _fals, _fals, _fals, _erro, _fals, _erro, _erro, _fals, _absn}, - /*MAP */ {_fals, _fals, _fals, _fals, _fals, _fals, _erro, _erro, _erro, _fals, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _fals, _erro}, - /*NULL */ {_true, _true, _true, _true, _true, _absn, _absn, _erro, _true, _true, _fals}, - /*ABSENT */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _erro, _true, _absn}, + /*INT */ {ge_b_ii, ge_b_if, _fals, ge_b_xs, ge_b_xs, _fals, _fals, gete, gete, _fals, _absn}, + /*FLOAT */ {ge_b_fi, ge_b_ff, _fals, ge_b_xs, ge_b_xs, _fals, _fals, gete, gete, _fals, _absn}, + /*BOOL */ {_fals, _fals, ge_b_bb, _fals, _fals, _fals, _fals, gete, gete, _fals, _absn}, + /*VOID */ {ge_b_sx, ge_b_sx, _fals, ge_b_ss, ge_b_ss, _fals, _fals, gete, gete, _fals, _absn}, + /*STRING */ {ge_b_sx, ge_b_sx, _fals, ge_b_ss, ge_b_ss, _fals, _fals, gete, gete, _fals, _absn}, + /*ARRAY */ {_fals, _fals, _fals, _fals, _fals, gete, _fals, gete, gete, _fals, _absn}, + /*MAP */ {_fals, _fals, _fals, _fals, _fals, _fals, gete, gete, gete, _fals, _absn}, + /*FUNC */ {gete, gete, gete, gete, gete, gete, gete, gete, gete, gete, gete}, + /*ERROR */ {gete, gete, gete, gete, gete, gete, gete, gete, gete, _fals, gete}, + /*NULL */ {_true, _true, _true, _true, _true, _absn, _absn, gete, _true, _true, _fals}, + /*ABSENT */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, gete, gete, _true, _absn}, +} + +func ltte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("<", input1, input2) } var lt_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {lt_b_ii, lt_b_if, _fals, lt_b_xs, lt_b_xs, _fals, _fals, _erro, _erro, _true, _absn}, - /*FLOAT */ {lt_b_fi, lt_b_ff, _fals, lt_b_xs, lt_b_xs, _fals, _fals, _erro, _erro, _true, _absn}, - /*BOOL */ {_fals, _fals, lt_b_bb, _fals, _fals, _fals, _fals, _erro, _erro, _true, _absn}, - /*VOID */ {lt_b_sx, lt_b_sx, _fals, lt_b_ss, lt_b_ss, _fals, _fals, _erro, _erro, _true, _absn}, - /*STRING */ {lt_b_sx, lt_b_sx, _fals, lt_b_ss, lt_b_ss, _fals, _fals, _erro, _erro, _true, _absn}, - /*ARRAY */ {_fals, _fals, _fals, _fals, _fals, _erro, _fals, _erro, _erro, _absn, _absn}, - /*MAP */ {_fals, _fals, _fals, _fals, _fals, _fals, _erro, _erro, _erro, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _true, _erro}, - /*NULL */ {_fals, _fals, _fals, _fals, _fals, _absn, _absn, _erro, _fals, _fals, _true}, - /*ABSENT */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _erro, _fals, _absn}, + /*INT */ {lt_b_ii, lt_b_if, _fals, lt_b_xs, lt_b_xs, _fals, _fals, ltte, ltte, _true, _absn}, + /*FLOAT */ {lt_b_fi, lt_b_ff, _fals, lt_b_xs, lt_b_xs, _fals, _fals, ltte, ltte, _true, _absn}, + /*BOOL */ {_fals, _fals, lt_b_bb, _fals, _fals, _fals, _fals, ltte, ltte, _true, _absn}, + /*VOID */ {lt_b_sx, lt_b_sx, _fals, lt_b_ss, lt_b_ss, _fals, _fals, ltte, ltte, _true, _absn}, + /*STRING */ {lt_b_sx, lt_b_sx, _fals, lt_b_ss, lt_b_ss, _fals, _fals, ltte, ltte, _true, _absn}, + /*ARRAY */ {_fals, _fals, _fals, _fals, _fals, ltte, _fals, ltte, ltte, _absn, _absn}, + /*MAP */ {_fals, _fals, _fals, _fals, _fals, _fals, ltte, ltte, ltte, _absn, _absn}, + /*FUNC */ {ltte, ltte, ltte, ltte, ltte, ltte, ltte, ltte, ltte, ltte, ltte}, + /*ERROR */ {ltte, ltte, ltte, ltte, ltte, ltte, ltte, ltte, ltte, _true, ltte}, + /*NULL */ {_fals, _fals, _fals, _fals, _fals, _absn, _absn, ltte, _fals, _fals, _true}, + /*ABSENT */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, ltte, ltte, _fals, _absn}, +} + +func lete(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("<=", input1, input2) } var le_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {le_b_ii, le_b_if, _fals, le_b_xs, le_b_xs, _fals, _fals, _erro, _erro, _true, _absn}, - /*FLOAT */ {le_b_fi, le_b_ff, _fals, le_b_xs, le_b_xs, _fals, _fals, _erro, _erro, _true, _absn}, - /*BOOL */ {_fals, _fals, le_b_bb, _fals, _fals, _fals, _fals, _erro, _erro, _true, _absn}, - /*VOID */ {le_b_sx, le_b_sx, _fals, le_b_ss, le_b_ss, _fals, _fals, _erro, _erro, _true, _absn}, - /*STRING */ {le_b_sx, le_b_sx, _fals, le_b_ss, le_b_ss, _fals, _fals, _erro, _erro, _true, _absn}, - /*ARRAY */ {_fals, _fals, _fals, _fals, _fals, _erro, _fals, _erro, _erro, _absn, _absn}, - /*MAP */ {_fals, _fals, _fals, _fals, _fals, _fals, _erro, _erro, _erro, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _true, _erro}, - /*NULL */ {_fals, _fals, _fals, _fals, _fals, _absn, _absn, _erro, _fals, _true, _true}, - /*ABSENT */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _erro, _fals, _absn}, + /*INT */ {le_b_ii, le_b_if, _fals, le_b_xs, le_b_xs, _fals, _fals, lete, lete, _true, _absn}, + /*FLOAT */ {le_b_fi, le_b_ff, _fals, le_b_xs, le_b_xs, _fals, _fals, lete, lete, _true, _absn}, + /*BOOL */ {_fals, _fals, le_b_bb, _fals, _fals, _fals, _fals, lete, lete, _true, _absn}, + /*VOID */ {le_b_sx, le_b_sx, _fals, le_b_ss, le_b_ss, _fals, _fals, lete, lete, _true, _absn}, + /*STRING */ {le_b_sx, le_b_sx, _fals, le_b_ss, le_b_ss, _fals, _fals, lete, lete, _true, _absn}, + /*ARRAY */ {_fals, _fals, _fals, _fals, _fals, lete, _fals, lete, lete, _absn, _absn}, + /*MAP */ {_fals, _fals, _fals, _fals, _fals, _fals, lete, lete, lete, _absn, _absn}, + /*FUNC */ {lete, lete, lete, lete, lete, lete, lete, lete, lete, lete, lete}, + /*ERROR */ {lete, lete, lete, lete, lete, lete, lete, lete, lete, _true, lete}, + /*NULL */ {_fals, _fals, _fals, _fals, _fals, _absn, _absn, lete, _fals, _true, _true}, + /*ABSENT */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, lete, lete, _fals, _absn}, +} + +func cmpte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("<=>", input1, input2) } var cmp_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {cmp_b_ii, cmp_b_if, _less, cmp_b_xs, cmp_b_xs, _less, _less, _erro, _erro, _true, _absn}, - /*FLOAT */ {cmp_b_fi, cmp_b_ff, _less, cmp_b_xs, cmp_b_xs, _less, _less, _erro, _erro, _true, _absn}, - /*BOOL */ {_more, _more, cmp_b_bb, _less, _less, _less, _less, _erro, _erro, _true, _absn}, - /*VOID */ {cmp_b_sx, cmp_b_sx, _more, cmp_b_ss, cmp_b_ss, _less, _less, _erro, _erro, _true, _absn}, - /*STRING */ {cmp_b_sx, cmp_b_sx, _more, cmp_b_ss, cmp_b_ss, _less, _less, _erro, _erro, _true, _absn}, - /*ARRAY */ {_more, _more, _more, _more, _more, _erro, _less, _erro, _erro, _absn, _absn}, - /*MAP */ {_more, _more, _more, _more, _more, _more, _erro, _erro, _erro, _absn, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _true, _erro}, - /*NULL */ {_more, _more, _more, _more, _more, _absn, _absn, _erro, _more, _same, _true}, - /*ABSENT */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _erro, _more, _absn}, + /*INT */ {cmp_b_ii, cmp_b_if, _less, cmp_b_xs, cmp_b_xs, _less, _less, cmpte, cmpte, _true, _absn}, + /*FLOAT */ {cmp_b_fi, cmp_b_ff, _less, cmp_b_xs, cmp_b_xs, _less, _less, cmpte, cmpte, _true, _absn}, + /*BOOL */ {_more, _more, cmp_b_bb, _less, _less, _less, _less, cmpte, cmpte, _true, _absn}, + /*VOID */ {cmp_b_sx, cmp_b_sx, _more, cmp_b_ss, cmp_b_ss, _less, _less, cmpte, cmpte, _true, _absn}, + /*STRING */ {cmp_b_sx, cmp_b_sx, _more, cmp_b_ss, cmp_b_ss, _less, _less, cmpte, cmpte, _true, _absn}, + /*ARRAY */ {_more, _more, _more, _more, _more, cmpte, _less, cmpte, cmpte, _absn, _absn}, + /*MAP */ {_more, _more, _more, _more, _more, _more, cmpte, cmpte, cmpte, _absn, _absn}, + /*FUNC */ {cmpte, cmpte, cmpte, cmpte, cmpte, cmpte, cmpte, cmpte, cmpte, cmpte, cmpte}, + /*ERROR */ {cmpte, cmpte, cmpte, cmpte, cmpte, cmpte, cmpte, cmpte, cmpte, _true, cmpte}, + /*NULL */ {_more, _more, _more, _more, _more, _absn, _absn, cmpte, _more, _same, _true}, + /*ABSENT */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, cmpte, cmpte, _more, _absn}, } func BIF_equals(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { From 22fedf3e60bf76af0ef8c79559ba13b7736969cf Mon Sep 17 00:00:00 2001 From: John Kerl Date: Mon, 28 Aug 2023 23:48:57 -0400 Subject: [PATCH 06/22] more --- internal/pkg/bifs/base.go | 10 ---- internal/pkg/bifs/collections.go | 16 ++++-- internal/pkg/bifs/mathlib.go | 84 ++++++++++++++++++-------------- internal/pkg/bifs/types.go | 50 ++++++++++++------- 4 files changed, 93 insertions(+), 67 deletions(-) diff --git a/internal/pkg/bifs/base.go b/internal/pkg/bifs/base.go index 4ae9326512..15e081f02f 100644 --- a/internal/pkg/bifs/base.go +++ b/internal/pkg/bifs/base.go @@ -106,11 +106,6 @@ func _type_error_unary(funcname string, input1 *mlrval.Mlrval) *mlrval.Mlrval { } // ---------------------------------------------------------------- -// Return error (unary) -func _erro1(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return mlrval.ERROR -} - // Return absent (unary) func _absn1(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.ABSENT @@ -156,11 +151,6 @@ func _type_error_binary(funcname string, input1, input2 *mlrval.Mlrval) *mlrval. ) } -// Return error (binary) -func _erro(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return mlrval.ERROR -} - // Return absent (binary) func _absn(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.ABSENT diff --git a/internal/pkg/bifs/collections.go b/internal/pkg/bifs/collections.go index 6dd523b6a8..db2e03857d 100644 --- a/internal/pkg/bifs/collections.go +++ b/internal/pkg/bifs/collections.go @@ -65,6 +65,10 @@ func depth_from_scalar(input1 *mlrval.Mlrval) *mlrval.Mlrval { // if this is defined statically. So, we use a "package init" function. var depth_dispositions = [mlrval.MT_DIM]UnaryFunc{} +func depth_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_unary("depth", input1) +} + func init() { depth_dispositions = [mlrval.MT_DIM]UnaryFunc{ /*INT */ depth_from_scalar, @@ -74,8 +78,8 @@ func init() { /*STRING */ depth_from_scalar, /*ARRAY */ depth_from_array, /*MAP */ depth_from_map, - /*FUNC */ _erro1, - /*ERROR */ _erro1, + /*FUNC */ depth_te, + /*ERROR */ depth_te, /*NULL */ _zero1, /*ABSENT */ _absn1, } @@ -134,6 +138,10 @@ func leafcount_from_scalar(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromInt(1) } +func leafcount_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_unary("leafcount", input1) +} + var leafcount_dispositions = [mlrval.MT_DIM]UnaryFunc{ /*INT */ leafcount_from_scalar, /*FLOAT */ leafcount_from_scalar, @@ -142,8 +150,8 @@ var leafcount_dispositions = [mlrval.MT_DIM]UnaryFunc{ /*STRING */ leafcount_from_scalar, /*ARRAY */ leafcount_from_array, /*MAP */ leafcount_from_map, - /*FUNC */ _erro1, - /*ERROR */ _erro1, + /*FUNC */ leafcount_te, + /*ERROR */ leafcount_te, /*NULL */ _zero1, /*ABSENT */ _absn1, } diff --git a/internal/pkg/bifs/mathlib.go b/internal/pkg/bifs/mathlib.go index 21f123ace0..c003b912ae 100644 --- a/internal/pkg/bifs/mathlib.go +++ b/internal/pkg/bifs/mathlib.go @@ -150,19 +150,23 @@ func pow_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(math.Pow(input1.AcquireFloatValue(), input2.AcquireFloatValue())) } +func powte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("**", input1, input2) +} + var pow_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ - // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {pow_f_ii, pow_f_if, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*FLOAT */ {pow_f_fi, pow_f_ff, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_i0__, _f0__, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT + /*INT */ {pow_f_ii, pow_f_if, powte, _void, powte, powte, powte, powte, powte, powte, _1___}, + /*FLOAT */ {pow_f_fi, pow_f_ff, powte, _void, powte, powte, powte, powte, powte, powte, _1___}, + /*BOOL */ {powte, powte, powte, powte, powte, powte, powte, powte, powte, powte, _absn}, + /*VOID */ {_void, _void, powte, _void, powte, powte, powte, powte, powte, powte, _absn}, + /*STRING */ {powte, powte, powte, powte, powte, powte, powte, powte, powte, powte, _absn}, + /*ARRAY */ {powte, powte, powte, powte, powte, powte, powte, powte, powte, powte, _absn}, + /*MAP */ {powte, powte, powte, powte, powte, powte, powte, powte, powte, powte, _absn}, + /*FUNC */ {powte, powte, powte, powte, powte, powte, powte, powte, powte, powte, _absn}, + /*ERROR */ {powte, powte, powte, powte, powte, powte, powte, powte, powte, powte, _absn}, + /*NULL */ {powte, powte, powte, powte, powte, powte, powte, powte, powte, powte, _absn}, + /*ABSENT */ {_i0__, _f0__, _absn, _absn, _absn, _absn, _absn, _absn, _absn, _absn, _absn}, } func BIF_pow(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -183,19 +187,23 @@ func atan2_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(math.Atan2(input1.AcquireFloatValue(), input2.AcquireFloatValue())) } +func atan2te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("atan2", input1, input2) +} + var atan2_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ - // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {atan2_f_ii, atan2_f_if, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*FLOAT */ {atan2_f_fi, atan2_f_ff, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_i0__, _f0__, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT + /*INT */ {atan2_f_ii, atan2_f_if, atan2te, _void, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, _1___}, + /*FLOAT */ {atan2_f_fi, atan2_f_ff, atan2te, _void, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, _1___}, + /*BOOL */ {atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, _absn}, + /*VOID */ {_void, _void, atan2te, _void, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, _absn}, + /*STRING */ {atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, _absn}, + /*ARRAY */ {atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, _absn}, + /*MAP */ {atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, _absn}, + /*FUNC */ {atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, _absn}, + /*ERROR */ {atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, _absn}, + /*NULL */ {atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, atan2te, _absn}, + /*ABSENT */ {_i0__, _f0__, atan2te, _absn, _absn, _absn, _absn, _absn, _absn, _absn, _absn}, } func BIF_atan2(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -220,19 +228,23 @@ func roundm_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(mlr_roundm(input1.AcquireFloatValue(), input2.AcquireFloatValue())) } +func rdmte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("roundm", input1, input2) +} + var roundm_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ - // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {roundm_f_ii, roundm_f_if, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*FLOAT */ {roundm_f_fi, roundm_f_ff, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _1___}, - /*BOOL */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*VOID */ {_void, _void, _erro, _void, _erro, _absn, _absn, _erro, _erro, _erro, _absn}, - /*STRING */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, _erro, _absn, _erro, _absn}, - /*FUNC */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro}, - /*ERROR */ {_erro, _erro, _erro, _erro, _erro, _absn, _absn, _erro, _erro, _erro, _erro}, - /*NULL */ {_erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _erro, _absn}, - /*ABSENT */ {_i0__, _f0__, _erro, _absn, _erro, _absn, _absn, _erro, _erro, _absn, _absn}, + // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT + /*INT */ {roundm_f_ii, roundm_f_if, rdmte, _void, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, _1___}, + /*FLOAT */ {roundm_f_fi, roundm_f_ff, rdmte, _void, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, _1___}, + /*BOOL */ {rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, _absn}, + /*VOID */ {_void, _void, rdmte, _void, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, _absn}, + /*STRING */ {rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, _absn}, + /*ARRAY */ {rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, _absn}, + /*MAP */ {rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, _absn}, + /*FUNC */ {rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, _absn}, + /*ERROR */ {rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, _absn}, + /*NULL */ {rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, rdmte, _absn}, + /*ABSENT */ {_i0__, _f0__, _absn, _absn, _absn, _absn, _absn, _absn, _absn, _absn, _absn}, } func BIF_roundm(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { diff --git a/internal/pkg/bifs/types.go b/internal/pkg/bifs/types.go index b876aa7802..200f6b6100 100644 --- a/internal/pkg/bifs/types.go +++ b/internal/pkg/bifs/types.go @@ -37,16 +37,20 @@ func bool_to_int(input1 *mlrval.Mlrval) *mlrval.Mlrval { } } +func to_int_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_unary("int", input1) +} + var to_int_dispositions = [mlrval.MT_DIM]UnaryFunc{ /*INT */ _1u___, /*FLOAT */ float_to_int, /*BOOL */ bool_to_int, /*VOID */ _void1, /*STRING */ string_to_int, - /*ARRAY */ _erro1, - /*MAP */ _erro1, - /*FUNC */ _erro1, - /*ERROR */ _erro1, + /*ARRAY */ to_int_te, + /*MAP */ to_int_te, + /*FUNC */ to_int_te, + /*ERROR */ to_int_te, /*NULL */ _null1, /*ABSENT */ _absn1, } @@ -81,23 +85,27 @@ func bool_to_int_with_base(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } } +func to_int_with_base_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("int", input1, input2) +} + var to_int_with_base_dispositions = [mlrval.MT_DIM]BinaryFunc{ /*INT */ int_to_int_with_base, /*FLOAT */ float_to_int_with_base, /*BOOL */ bool_to_int_with_base, /*VOID */ _void, /*STRING */ string_to_int_with_base, - /*ARRAY */ _erro, - /*MAP */ _erro, - /*FUNC */ _erro, - /*ERROR */ _erro, + /*ARRAY */ to_int_with_base_te, + /*MAP */ to_int_with_base_te, + /*FUNC */ to_int_with_base_te, + /*ERROR */ to_int_with_base_te, /*NULL */ _null, /*ABSENT */ _absn, } func BIF_int_with_base(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsInt() { - return mlrval.ERROR + return _type_error_binary("int", input1, input2) } return to_int_with_base_dispositions[input1.Type()](input1, input2) } @@ -124,16 +132,20 @@ func bool_to_float(input1 *mlrval.Mlrval) *mlrval.Mlrval { } } +func to_float_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_unary("float", input1) +} + var to_float_dispositions = [mlrval.MT_DIM]UnaryFunc{ /*INT */ int_to_float, /*FLOAT */ _1u___, /*BOOL */ bool_to_float, /*VOID */ _void1, /*STRING */ string_to_float, - /*ARRAY */ _erro1, - /*MAP */ _erro1, - /*FUNC */ _erro1, - /*ERROR */ _erro1, + /*ARRAY */ to_float_te, + /*MAP */ to_float_te, + /*FUNC */ to_float_te, + /*ERROR */ to_float_te, /*NULL */ _null1, /*ABSENT */ _absn1, } @@ -160,16 +172,20 @@ func float_to_bool(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromBool(input1.AcquireFloatValue() != 0.0) } +func to_boolean_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_unary("boolean", input1) +} + var to_boolean_dispositions = [mlrval.MT_DIM]UnaryFunc{ /*INT */ int_to_bool, /*FLOAT */ float_to_bool, /*BOOL */ _1u___, /*VOID */ _void1, /*STRING */ string_to_boolean, - /*ARRAY */ _erro1, - /*MAP */ _erro1, - /*FUNC */ _erro1, - /*ERROR */ _erro1, + /*ARRAY */ to_boolean_te, + /*MAP */ to_boolean_te, + /*FUNC */ to_boolean_te, + /*ERROR */ to_boolean_te, /*NULL */ _null1, /*ABSENT */ _absn1, } From 725a7d027e8b484d2da6e5e824a6e18e740cf502 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Mon, 28 Aug 2023 23:55:07 -0400 Subject: [PATCH 07/22] more --- internal/pkg/bifs/arithmetic.go | 264 ++++++++++++++++---------------- internal/pkg/bifs/mathlib.go | 10 +- 2 files changed, 139 insertions(+), 135 deletions(-) diff --git a/internal/pkg/bifs/arithmetic.go b/internal/pkg/bifs/arithmetic.go index aded7bda4d..2213422186 100644 --- a/internal/pkg/bifs/arithmetic.go +++ b/internal/pkg/bifs/arithmetic.go @@ -104,23 +104,23 @@ func plus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() + input2.AcquireFloatValue()) } -func plus_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { +func plste(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return _type_error_binary("+", input1, input2) } var plus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {plus_n_ii, plus_f_if, plus_te, _1___, plus_te, _absn, _absn, plus_te, plus_te, _1___, _1___}, - /*FLOAT */ {plus_f_fi, plus_f_ff, plus_te, _1___, plus_te, _absn, _absn, plus_te, plus_te, _1___, _1___}, - /*BOOL */ {plus_te, plus_te, plus_te, plus_te, plus_te, _absn, _absn, plus_te, plus_te, plus_te, plus_te}, - /*VOID */ {_2___, _2___, plus_te, _void, plus_te, _absn, _absn, plus_te, plus_te, plus_te, _absn}, - /*STRING */ {plus_te, plus_te, plus_te, plus_te, plus_te, _absn, _absn, plus_te, plus_te, plus_te, plus_te}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, plus_te, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, plus_te, _absn, _absn, _absn}, - /*FUNC */ {plus_te, plus_te, plus_te, plus_te, plus_te, plus_te, plus_te, plus_te, plus_te, plus_te, plus_te}, - /*ERROR */ {plus_te, plus_te, plus_te, plus_te, plus_te, _absn, _absn, plus_te, plus_te, plus_te, plus_te}, - /*NULL */ {_2___, _2___, plus_te, plus_te, plus_te, _absn, _absn, plus_te, plus_te, _null, _absn}, - /*ABSENT */ {_2___, _2___, plus_te, _absn, plus_te, _absn, _absn, plus_te, plus_te, _absn, _absn}, + /*INT */ {plus_n_ii, plus_f_if, plste, _1___, plste, _absn, _absn, plste, plste, _1___, _1___}, + /*FLOAT */ {plus_f_fi, plus_f_ff, plste, _1___, plste, _absn, _absn, plste, plste, _1___, _1___}, + /*BOOL */ {plste, plste, plste, plste, plste, _absn, _absn, plste, plste, plste, plste}, + /*VOID */ {_2___, _2___, plste, _void, plste, _absn, _absn, plste, plste, plste, _absn}, + /*STRING */ {plste, plste, plste, plste, plste, _absn, _absn, plste, plste, plste, plste}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, plste, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, plste, _absn, _absn, _absn}, + /*FUNC */ {plste, plste, plste, plste, plste, plste, plste, plste, plste, plste, plste}, + /*ERROR */ {plste, plste, plste, plste, plste, _absn, _absn, plste, plste, plste, plste}, + /*NULL */ {_2___, _2___, plste, plste, plste, _absn, _absn, plste, plste, _null, _absn}, + /*ABSENT */ {_2___, _2___, plste, _absn, plste, _absn, _absn, plste, plste, _absn, _absn}, } func BIF_plus_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -166,23 +166,23 @@ func minus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() - input2.AcquireFloatValue()) } -func minus_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { +func mnste(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return _type_error_binary("-", input1, input2) } var minus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {minus_n_ii, minus_f_if, minus_te, _1___, minus_te, _absn, _absn, minus_te, minus_te, _1___, _1___}, - /*FLOAT */ {minus_f_fi, minus_f_ff, minus_te, _1___, minus_te, _absn, _absn, minus_te, minus_te, _1___, _1___}, - /*BOOL */ {minus_te, minus_te, minus_te, minus_te, minus_te, _absn, _absn, minus_te, minus_te, minus_te, minus_te}, - /*VOID */ {_n2__, _n2__, minus_te, _void, minus_te, _absn, _absn, minus_te, minus_te, minus_te, _absn}, - /*STRING */ {minus_te, minus_te, minus_te, minus_te, minus_te, _absn, _absn, minus_te, minus_te, minus_te, minus_te}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, minus_te, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, minus_te, _absn, _absn, _absn}, - /*FUNC */ {minus_te, minus_te, minus_te, minus_te, minus_te, minus_te, minus_te, minus_te, minus_te, minus_te, minus_te}, - /*ERROR */ {minus_te, minus_te, minus_te, minus_te, minus_te, _absn, _absn, minus_te, minus_te, minus_te, minus_te}, - /*NULL */ {_2___, _2___, minus_te, minus_te, minus_te, _absn, _absn, minus_te, minus_te, _null, _absn}, - /*ABSENT */ {_2___, _2___, minus_te, _absn, minus_te, _absn, _absn, minus_te, minus_te, _absn, _absn}, + /*INT */ {minus_n_ii, minus_f_if, mnste, _1___, mnste, _absn, _absn, mnste, mnste, _1___, _1___}, + /*FLOAT */ {minus_f_fi, minus_f_ff, mnste, _1___, mnste, _absn, _absn, mnste, mnste, _1___, _1___}, + /*BOOL */ {mnste, mnste, mnste, mnste, mnste, _absn, _absn, mnste, mnste, mnste, mnste}, + /*VOID */ {_n2__, _n2__, mnste, _void, mnste, _absn, _absn, mnste, mnste, mnste, _absn}, + /*STRING */ {mnste, mnste, mnste, mnste, mnste, _absn, _absn, mnste, mnste, mnste, mnste}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, mnste, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, mnste, _absn, _absn, _absn}, + /*FUNC */ {mnste, mnste, mnste, mnste, mnste, mnste, mnste, mnste, mnste, mnste, mnste}, + /*ERROR */ {mnste, mnste, mnste, mnste, mnste, _absn, _absn, mnste, mnste, mnste, mnste}, + /*NULL */ {_2___, _2___, mnste, mnste, mnste, _absn, _absn, mnste, mnste, _null, _absn}, + /*ABSENT */ {_2___, _2___, mnste, _absn, mnste, _absn, _absn, mnste, mnste, _absn, _absn}, } func BIF_minus_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -244,23 +244,23 @@ func times_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() * input2.AcquireFloatValue()) } -func times_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { +func tmste(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return _type_error_binary("*", input1, input2) } var times_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {times_n_ii, times_f_if, times_te, _1___, times_te, _absn, _absn, times_te, times_te, _1___, _1___}, - /*FLOAT */ {times_f_fi, times_f_ff, times_te, _1___, times_te, _absn, _absn, times_te, times_te, _1___, _1___}, - /*BOOL */ {times_te, times_te, times_te, times_te, times_te, _absn, _absn, times_te, times_te, times_te, times_te}, - /*VOID */ {_2___, _2___, times_te, _void, times_te, _absn, _absn, times_te, times_te, times_te, _absn}, - /*STRING */ {times_te, times_te, times_te, times_te, times_te, _absn, _absn, times_te, times_te, times_te, times_te}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, times_te, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, times_te, _absn, _absn, _absn}, - /*FUNC */ {times_te, times_te, times_te, times_te, times_te, times_te, times_te, times_te, times_te, times_te, times_te}, - /*ERROR */ {times_te, times_te, times_te, times_te, times_te, _absn, _absn, times_te, times_te, times_te, times_te}, - /*NULL */ {_2___, _2___, times_te, times_te, times_te, _absn, _absn, times_te, times_te, _null, _absn}, - /*ABSENT */ {_2___, _2___, times_te, _absn, times_te, _absn, _absn, times_te, times_te, _absn, _absn}, + /*INT */ {times_n_ii, times_f_if, tmste, _1___, tmste, _absn, _absn, tmste, tmste, _1___, _1___}, + /*FLOAT */ {times_f_fi, times_f_ff, tmste, _1___, tmste, _absn, _absn, tmste, tmste, _1___, _1___}, + /*BOOL */ {tmste, tmste, tmste, tmste, tmste, _absn, _absn, tmste, tmste, tmste, tmste}, + /*VOID */ {_2___, _2___, tmste, _void, tmste, _absn, _absn, tmste, tmste, tmste, _absn}, + /*STRING */ {tmste, tmste, tmste, tmste, tmste, _absn, _absn, tmste, tmste, tmste, tmste}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, tmste, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, tmste, _absn, _absn, _absn}, + /*FUNC */ {tmste, tmste, tmste, tmste, tmste, tmste, tmste, tmste, tmste, tmste, tmste}, + /*ERROR */ {tmste, tmste, tmste, tmste, tmste, _absn, _absn, tmste, tmste, tmste, tmste}, + /*NULL */ {_2___, _2___, tmste, tmste, tmste, _absn, _absn, tmste, tmste, _null, _absn}, + /*ABSENT */ {_2___, _2___, tmste, _absn, tmste, _absn, _absn, tmste, tmste, _absn, _absn}, } func BIF_times(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -311,23 +311,23 @@ func divide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() / input2.AcquireFloatValue()) } -func divide_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { +func dvdte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return _type_error_binary("/", input1, input2) } var divide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {divide_n_ii, divide_f_if, divide_te, _void, divide_te, _absn, _absn, divide_te, divide_te, _1___, _1___}, - /*FLOAT */ {divide_f_fi, divide_f_ff, divide_te, _void, divide_te, _absn, _absn, divide_te, divide_te, _1___, _1___}, - /*BOOL */ {divide_te, divide_te, divide_te, divide_te, divide_te, _absn, _absn, divide_te, divide_te, divide_te, divide_te}, - /*VOID */ {_void, _void, divide_te, _void, divide_te, _absn, _absn, divide_te, divide_te, divide_te, _absn}, - /*STRING */ {divide_te, divide_te, divide_te, divide_te, divide_te, _absn, _absn, divide_te, divide_te, divide_te, divide_te}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, divide_te, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, divide_te, _absn, _absn, _absn}, - /*FUNC */ {divide_te, divide_te, divide_te, divide_te, divide_te, divide_te, divide_te, divide_te, divide_te, divide_te, divide_te}, - /*ERROR */ {divide_te, divide_te, divide_te, divide_te, divide_te, _absn, _absn, divide_te, divide_te, divide_te, divide_te}, - /*NULL */ {_i0__, _f0__, divide_te, divide_te, divide_te, _absn, _absn, divide_te, divide_te, divide_te, _absn}, - /*ABSENT */ {_i0__, _f0__, divide_te, _absn, divide_te, _absn, _absn, divide_te, divide_te, _absn, _absn}, + /*INT */ {divide_n_ii, divide_f_if, dvdte, _void, dvdte, _absn, _absn, dvdte, dvdte, _1___, _1___}, + /*FLOAT */ {divide_f_fi, divide_f_ff, dvdte, _void, dvdte, _absn, _absn, dvdte, dvdte, _1___, _1___}, + /*BOOL */ {dvdte, dvdte, dvdte, dvdte, dvdte, _absn, _absn, dvdte, dvdte, dvdte, dvdte}, + /*VOID */ {_void, _void, dvdte, _void, dvdte, _absn, _absn, dvdte, dvdte, dvdte, _absn}, + /*STRING */ {dvdte, dvdte, dvdte, dvdte, dvdte, _absn, _absn, dvdte, dvdte, dvdte, dvdte}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dvdte, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dvdte, _absn, _absn, _absn}, + /*FUNC */ {dvdte, dvdte, dvdte, dvdte, dvdte, dvdte, dvdte, dvdte, dvdte, dvdte, dvdte}, + /*ERROR */ {dvdte, dvdte, dvdte, dvdte, dvdte, _absn, _absn, dvdte, dvdte, dvdte, dvdte}, + /*NULL */ {_i0__, _f0__, dvdte, dvdte, dvdte, _absn, _absn, dvdte, dvdte, dvdte, _absn}, + /*ABSENT */ {_i0__, _f0__, dvdte, _absn, dvdte, _absn, _absn, dvdte, dvdte, _absn, _absn}, } func BIF_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -376,23 +376,23 @@ func int_divide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(math.Floor(input1.AcquireFloatValue() / input2.AcquireFloatValue())) } -func idivide_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { +func idvte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return _type_error_binary("//", input1, input2) } var int_divide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {int_divide_n_ii, int_divide_f_if, idivide_te, _void, idivide_te, _absn, _absn, idivide_te, idivide_te, idivide_te, _1___}, - /*FLOAT */ {int_divide_f_fi, int_divide_f_ff, idivide_te, _void, idivide_te, _absn, _absn, idivide_te, idivide_te, idivide_te, _1___}, - /*BOOL */ {idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, _absn, _absn, idivide_te, idivide_te, idivide_te, idivide_te}, - /*VOID */ {_void, _void, idivide_te, _void, idivide_te, _absn, _absn, idivide_te, idivide_te, idivide_te, _absn}, - /*STRING */ {idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, _absn, _absn, idivide_te, idivide_te, idivide_te, idivide_te}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, idivide_te, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, idivide_te, _absn, _absn, _absn}, - /*FUNC */ {idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, idivide_te}, - /*ERROR */ {idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, _absn, _absn, idivide_te, idivide_te, idivide_te, idivide_te}, - /*NULL */ {idivide_te, idivide_te, idivide_te, idivide_te, idivide_te, _absn, _absn, idivide_te, idivide_te, idivide_te, _absn}, - /*ABSENT */ {_i0__, _f0__, idivide_te, _absn, idivide_te, _absn, _absn, idivide_te, idivide_te, _absn, _absn}, + /*INT */ {int_divide_n_ii, int_divide_f_if, idvte, _void, idvte, _absn, _absn, idvte, idvte, idvte, _1___}, + /*FLOAT */ {int_divide_f_fi, int_divide_f_ff, idvte, _void, idvte, _absn, _absn, idvte, idvte, idvte, _1___}, + /*BOOL */ {idvte, idvte, idvte, idvte, idvte, _absn, _absn, idvte, idvte, idvte, idvte}, + /*VOID */ {_void, _void, idvte, _void, idvte, _absn, _absn, idvte, idvte, idvte, _absn}, + /*STRING */ {idvte, idvte, idvte, idvte, idvte, _absn, _absn, idvte, idvte, idvte, idvte}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, idvte, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, idvte, _absn, _absn, _absn}, + /*FUNC */ {idvte, idvte, idvte, idvte, idvte, idvte, idvte, idvte, idvte, idvte, idvte}, + /*ERROR */ {idvte, idvte, idvte, idvte, idvte, _absn, _absn, idvte, idvte, idvte, idvte}, + /*NULL */ {idvte, idvte, idvte, idvte, idvte, _absn, _absn, idvte, idvte, idvte, _absn}, + /*ABSENT */ {_i0__, _f0__, idvte, _absn, idvte, _absn, _absn, idvte, idvte, _absn, _absn}, } func BIF_int_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -416,23 +416,23 @@ func dotplus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() + input2.AcquireFloatValue()) } -func dotplus_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { +func dplte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return _type_error_binary(".+", input1, input2) } var dot_plus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {dotplus_i_ii, dotplus_f_if, dotplus_te, _1___, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, _1___, _1___}, - /*FLOAT */ {dotplus_f_fi, dotplus_f_ff, dotplus_te, _1___, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, _1___, _1___}, - /*BOOL */ {dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, dotplus_te, dotplus_te}, - /*VOID */ {_2___, _2___, dotplus_te, _void, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, dotplus_te, _absn}, - /*STRING */ {dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, dotplus_te, dotplus_te}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotplus_te, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotplus_te, _absn, _absn, _absn}, - /*FUNC */ {dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te}, - /*ERROR */ {dotplus_te, dotplus_te, dotplus_te, dotplus_te, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, dotplus_te, dotplus_te}, - /*NULL */ {_2___, _2___, dotplus_te, dotplus_te, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, _null, _absn}, - /*ABSENT */ {_2___, _2___, dotplus_te, _absn, dotplus_te, _absn, _absn, dotplus_te, dotplus_te, _absn, _absn}, + /*INT */ {dotplus_i_ii, dotplus_f_if, dplte, _1___, dplte, _absn, _absn, dplte, dplte, _1___, _1___}, + /*FLOAT */ {dotplus_f_fi, dotplus_f_ff, dplte, _1___, dplte, _absn, _absn, dplte, dplte, _1___, _1___}, + /*BOOL */ {dplte, dplte, dplte, dplte, dplte, _absn, _absn, dplte, dplte, dplte, dplte}, + /*VOID */ {_2___, _2___, dplte, _void, dplte, _absn, _absn, dplte, dplte, dplte, _absn}, + /*STRING */ {dplte, dplte, dplte, dplte, dplte, _absn, _absn, dplte, dplte, dplte, dplte}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dplte, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dplte, _absn, _absn, _absn}, + /*FUNC */ {dplte, dplte, dplte, dplte, dplte, dplte, dplte, dplte, dplte, dplte, dplte}, + /*ERROR */ {dplte, dplte, dplte, dplte, dplte, _absn, _absn, dplte, dplte, dplte, dplte}, + /*NULL */ {_2___, _2___, dplte, dplte, dplte, _absn, _absn, dplte, dplte, _null, _absn}, + /*ABSENT */ {_2___, _2___, dplte, _absn, dplte, _absn, _absn, dplte, dplte, _absn, _absn}, } func BIF_dot_plus(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -456,23 +456,23 @@ func dotminus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() - input2.AcquireFloatValue()) } -func dotminus_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { +func dmnte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return _type_error_binary(".-", input1, input2) } var dotminus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {dotminus_i_ii, dotminus_f_if, dotminus_te, _1___, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, _1___, _1___}, - /*FLOAT */ {dotminus_f_fi, dotminus_f_ff, dotminus_te, _1___, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, _1___, _1___}, - /*BOOL */ {dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, dotminus_te, dotminus_te}, - /*VOID */ {_n2__, _n2__, dotminus_te, _void, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, dotminus_te, _absn}, - /*STRING */ {dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, dotminus_te, dotminus_te}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotminus_te, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotminus_te, _absn, _absn, _absn}, - /*FUNC */ {dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te}, - /*ERROR */ {dotminus_te, dotminus_te, dotminus_te, dotminus_te, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, dotminus_te, dotminus_te}, - /*NULL */ {_n2__, _n2__, dotminus_te, dotminus_te, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, _null, _absn}, - /*ABSENT */ {_n2__, _n2__, dotminus_te, _absn, dotminus_te, _absn, _absn, dotminus_te, dotminus_te, _absn, _absn}, + /*INT */ {dotminus_i_ii, dotminus_f_if, dmnte, _1___, dmnte, _absn, _absn, dmnte, dmnte, _1___, _1___}, + /*FLOAT */ {dotminus_f_fi, dotminus_f_ff, dmnte, _1___, dmnte, _absn, _absn, dmnte, dmnte, _1___, _1___}, + /*BOOL */ {dmnte, dmnte, dmnte, dmnte, dmnte, _absn, _absn, dmnte, dmnte, dmnte, dmnte}, + /*VOID */ {_n2__, _n2__, dmnte, _void, dmnte, _absn, _absn, dmnte, dmnte, dmnte, _absn}, + /*STRING */ {dmnte, dmnte, dmnte, dmnte, dmnte, _absn, _absn, dmnte, dmnte, dmnte, dmnte}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dmnte, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dmnte, _absn, _absn, _absn}, + /*FUNC */ {dmnte, dmnte, dmnte, dmnte, dmnte, dmnte, dmnte, dmnte, dmnte, dmnte, dmnte}, + /*ERROR */ {dmnte, dmnte, dmnte, dmnte, dmnte, _absn, _absn, dmnte, dmnte, dmnte, dmnte}, + /*NULL */ {_n2__, _n2__, dmnte, dmnte, dmnte, _absn, _absn, dmnte, dmnte, _null, _absn}, + /*ABSENT */ {_n2__, _n2__, dmnte, _absn, dmnte, _absn, _absn, dmnte, dmnte, _absn, _absn}, } func BIF_dot_minus(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -496,23 +496,23 @@ func dottimes_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() * input2.AcquireFloatValue()) } -func dottimes_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { +func dttte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return _type_error_binary(".*", input1, input2) } var dottimes_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {dottimes_i_ii, dottimes_f_if, dottimes_te, _1___, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, _1___, _1___}, - /*FLOAT */ {dottimes_f_fi, dottimes_f_ff, dottimes_te, _1___, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, _1___, _1___}, - /*BOOL */ {dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, dottimes_te, dottimes_te}, - /*VOID */ {_n2__, _n2__, dottimes_te, _void, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, dottimes_te, _absn}, - /*STRING */ {dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, dottimes_te, dottimes_te}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dottimes_te, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dottimes_te, _absn, _absn, _absn}, - /*FUNC */ {dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te}, - /*ERROR */ {dottimes_te, dottimes_te, dottimes_te, dottimes_te, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, dottimes_te, dottimes_te}, - /*NULL */ {_2___, _2___, dottimes_te, dottimes_te, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, dottimes_te, _absn}, - /*ABSENT */ {_2___, _2___, dottimes_te, _absn, dottimes_te, _absn, _absn, dottimes_te, dottimes_te, _absn, _absn}, + /*INT */ {dottimes_i_ii, dottimes_f_if, dttte, _1___, dttte, _absn, _absn, dttte, dttte, _1___, _1___}, + /*FLOAT */ {dottimes_f_fi, dottimes_f_ff, dttte, _1___, dttte, _absn, _absn, dttte, dttte, _1___, _1___}, + /*BOOL */ {dttte, dttte, dttte, dttte, dttte, _absn, _absn, dttte, dttte, dttte, dttte}, + /*VOID */ {_n2__, _n2__, dttte, _void, dttte, _absn, _absn, dttte, dttte, dttte, _absn}, + /*STRING */ {dttte, dttte, dttte, dttte, dttte, _absn, _absn, dttte, dttte, dttte, dttte}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dttte, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dttte, _absn, _absn, _absn}, + /*FUNC */ {dttte, dttte, dttte, dttte, dttte, dttte, dttte, dttte, dttte, dttte, dttte}, + /*ERROR */ {dttte, dttte, dttte, dttte, dttte, _absn, _absn, dttte, dttte, dttte, dttte}, + /*NULL */ {_2___, _2___, dttte, dttte, dttte, _absn, _absn, dttte, dttte, dttte, _absn}, + /*ABSENT */ {_2___, _2___, dttte, _absn, dttte, _absn, _absn, dttte, dttte, _absn, _absn}, } func BIF_dot_times(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -536,23 +536,23 @@ func dotdivide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(input1.AcquireFloatValue() / input2.AcquireFloatValue()) } -func dotdivide_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { +func ddvte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return _type_error_binary("./", input1, input2) } var dotdivide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {dotdivide_i_ii, dotdivide_f_if, dotdivide_te, _void, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, dotdivide_te, _1___}, - /*FLOAT */ {dotdivide_f_fi, dotdivide_f_ff, dotdivide_te, _void, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, dotdivide_te, _1___}, - /*BOOL */ {dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te}, - /*VOID */ {_void, _void, dotdivide_te, _void, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, dotdivide_te, _absn}, - /*STRING */ {dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotdivide_te, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotdivide_te, _absn, _absn, _absn}, - /*FUNC */ {dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te}, - /*ERROR */ {dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te}, - /*NULL */ {dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, dotdivide_te, _absn}, - /*ABSENT */ {_2___, _2___, dotdivide_te, _absn, dotdivide_te, _absn, _absn, dotdivide_te, dotdivide_te, _absn, _absn}, + /*INT */ {dotdivide_i_ii, dotdivide_f_if, ddvte, _void, ddvte, _absn, _absn, ddvte, ddvte, ddvte, _1___}, + /*FLOAT */ {dotdivide_f_fi, dotdivide_f_ff, ddvte, _void, ddvte, _absn, _absn, ddvte, ddvte, ddvte, _1___}, + /*BOOL */ {ddvte, ddvte, ddvte, ddvte, ddvte, _absn, _absn, ddvte, ddvte, ddvte, ddvte}, + /*VOID */ {_void, _void, ddvte, _void, ddvte, _absn, _absn, ddvte, ddvte, ddvte, _absn}, + /*STRING */ {ddvte, ddvte, ddvte, ddvte, ddvte, _absn, _absn, ddvte, ddvte, ddvte, ddvte}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, ddvte, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, ddvte, _absn, _absn, _absn}, + /*FUNC */ {ddvte, ddvte, ddvte, ddvte, ddvte, ddvte, ddvte, ddvte, ddvte, ddvte, ddvte}, + /*ERROR */ {ddvte, ddvte, ddvte, ddvte, ddvte, _absn, _absn, ddvte, ddvte, ddvte, ddvte}, + /*NULL */ {ddvte, ddvte, ddvte, ddvte, ddvte, _absn, _absn, ddvte, ddvte, ddvte, _absn}, + /*ABSENT */ {_2___, _2___, ddvte, _absn, ddvte, _absn, _absn, ddvte, ddvte, _absn, _absn}, } func BIF_dot_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -601,23 +601,23 @@ func dotidivide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(math.Floor(input1.AcquireFloatValue() / input2.AcquireFloatValue())) } -func dotidivide_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { +func didte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return _type_error_binary(".//", input1, input2) } var dotidivide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {dotidivide_i_ii, dotidivide_f_if, dotidivide_te, _void, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, _1___}, - /*FLOAT */ {dotidivide_f_fi, dotidivide_f_ff, dotidivide_te, _void, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, _1___}, - /*BOOL */ {dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te}, - /*VOID */ {_void, _void, dotidivide_te, _void, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, _absn}, - /*STRING */ {dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotidivide_te, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, dotidivide_te, _absn, _absn, _absn}, - /*FUNC */ {dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te}, - /*ERROR */ {dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te}, - /*NULL */ {dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, _absn}, - /*ABSENT */ {_2___, _2___, dotidivide_te, _absn, dotidivide_te, _absn, _absn, dotidivide_te, dotidivide_te, dotidivide_te, _absn}, + /*INT */ {dotidivide_i_ii, dotidivide_f_if, didte, _void, didte, _absn, _absn, didte, didte, didte, _1___}, + /*FLOAT */ {dotidivide_f_fi, dotidivide_f_ff, didte, _void, didte, _absn, _absn, didte, didte, didte, _1___}, + /*BOOL */ {didte, didte, didte, didte, didte, _absn, _absn, didte, didte, didte, didte}, + /*VOID */ {_void, _void, didte, _void, didte, _absn, _absn, didte, didte, didte, _absn}, + /*STRING */ {didte, didte, didte, didte, didte, _absn, _absn, didte, didte, didte, didte}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, didte, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, didte, _absn, _absn, _absn}, + /*FUNC */ {didte, didte, didte, didte, didte, didte, didte, didte, didte, didte, didte}, + /*ERROR */ {didte, didte, didte, didte, didte, _absn, _absn, didte, didte, didte, didte}, + /*NULL */ {didte, didte, didte, didte, didte, _absn, _absn, didte, didte, didte, _absn}, + /*ABSENT */ {_2___, _2___, didte, _absn, didte, _absn, _absn, didte, didte, didte, _absn}, } func BIF_dot_int_divide(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { @@ -669,23 +669,23 @@ func modulus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromFloat(a - b*math.Floor(a/b)) } -func modulus_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { +func modte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return _type_error_binary("%", input1, input2) } var modulus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ // . INT FLOAT BOOL VOID STRING ARRAY MAP FUNC ERROR NULL ABSENT - /*INT */ {modulus_i_ii, modulus_f_if, modulus_te, _void, modulus_te, _absn, _absn, modulus_te, modulus_te, modulus_te, _1___}, - /*FLOAT */ {modulus_f_fi, modulus_f_ff, modulus_te, _void, modulus_te, _absn, _absn, modulus_te, modulus_te, modulus_te, _1___}, - /*BOOL */ {modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, _absn, _absn, modulus_te, modulus_te, modulus_te, modulus_te}, - /*VOID */ {_void, _void, modulus_te, _void, modulus_te, _absn, _absn, modulus_te, modulus_te, modulus_te, _absn}, - /*STRING */ {modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, _absn, _absn, modulus_te, modulus_te, modulus_te, modulus_te}, - /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, modulus_te, _absn, _absn, _absn}, - /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, modulus_te, _absn, _absn, _absn}, - /*FUNC */ {modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, modulus_te}, - /*ERROR */ {modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, _absn, _absn, modulus_te, modulus_te, modulus_te, modulus_te}, - /*NULL */ {modulus_te, modulus_te, modulus_te, modulus_te, modulus_te, _absn, _absn, modulus_te, modulus_te, modulus_te, _absn}, - /*ABSENT */ {_i0__, _f0__, modulus_te, _absn, modulus_te, _absn, _absn, modulus_te, modulus_te, _absn, _absn}, + /*INT */ {modulus_i_ii, modulus_f_if, modte, _void, modte, _absn, _absn, modte, modte, modte, _1___}, + /*FLOAT */ {modulus_f_fi, modulus_f_ff, modte, _void, modte, _absn, _absn, modte, modte, modte, _1___}, + /*BOOL */ {modte, modte, modte, modte, modte, _absn, _absn, modte, modte, modte, modte}, + /*VOID */ {_void, _void, modte, _void, modte, _absn, _absn, modte, modte, modte, _absn}, + /*STRING */ {modte, modte, modte, modte, modte, _absn, _absn, modte, modte, modte, modte}, + /*ARRAY */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, modte, _absn, _absn, _absn}, + /*MAP */ {_absn, _absn, _absn, _absn, _absn, _absn, _absn, modte, _absn, _absn, _absn}, + /*FUNC */ {modte, modte, modte, modte, modte, modte, modte, modte, modte, modte, modte}, + /*ERROR */ {modte, modte, modte, modte, modte, _absn, _absn, modte, modte, modte, modte}, + /*NULL */ {modte, modte, modte, modte, modte, _absn, _absn, modte, modte, modte, _absn}, + /*ABSENT */ {_i0__, _f0__, modte, _absn, modte, _absn, _absn, modte, modte, _absn, _absn}, } func BIF_modulus(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { diff --git a/internal/pkg/bifs/mathlib.go b/internal/pkg/bifs/mathlib.go index c003b912ae..3f2b290863 100644 --- a/internal/pkg/bifs/mathlib.go +++ b/internal/pkg/bifs/mathlib.go @@ -252,6 +252,10 @@ func BIF_roundm(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } // ================================================================ +func logifit_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { + return _type_error_binary("logifit", input1, input2) +} + func BIF_logifit(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsLegit() { return input1 @@ -266,15 +270,15 @@ func BIF_logifit(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { // int/float OK; rest not x, xok := input1.GetNumericToFloatValue() if !xok { - return mlrval.ERROR + return logifit_te(input1, input2) } m, mok := input2.GetNumericToFloatValue() if !mok { - return mlrval.ERROR + return logifit_te(input1, input2) } b, bok := input3.GetNumericToFloatValue() if !bok { - return mlrval.ERROR + return logifit_te(input1, input2) } return mlrval.FromFloat(1.0 / (1.0 + math.Exp(-m*x-b))) From c1e7ad28b0f2ced63aad37afa71105f6c07b6a0b Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 29 Aug 2023 00:03:30 -0400 Subject: [PATCH 08/22] more --- internal/pkg/bifs/booleans.go | 8 ++++---- internal/pkg/bifs/strings.go | 30 +++++++++++++++--------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/internal/pkg/bifs/booleans.go b/internal/pkg/bifs/booleans.go index cef3387d53..b51a967bce 100644 --- a/internal/pkg/bifs/booleans.go +++ b/internal/pkg/bifs/booleans.go @@ -12,7 +12,7 @@ func BIF_logical_NOT(input1 *mlrval.Mlrval) *mlrval.Mlrval { if input1.IsBool() { return mlrval.FromBool(!input1.AcquireBoolValue()) } else { - return mlrval.ERROR + return _type_error_unary("!", input1) } } @@ -20,7 +20,7 @@ func BIF_logical_AND(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if input1.IsBool() && input2.IsBool() { return mlrval.FromBool(input1.AcquireBoolValue() && input2.AcquireBoolValue()) } else { - return mlrval.ERROR + return _type_error_unary("&&", input1) } } @@ -28,7 +28,7 @@ func BIF_logical_OR(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if input1.IsBool() && input2.IsBool() { return mlrval.FromBool(input1.AcquireBoolValue() || input2.AcquireBoolValue()) } else { - return mlrval.ERROR + return _type_error_unary("||", input1) } } @@ -36,6 +36,6 @@ func BIF_logical_XOR(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if input1.IsBool() && input2.IsBool() { return mlrval.FromBool(input1.AcquireBoolValue() != input2.AcquireBoolValue()) } else { - return mlrval.ERROR + return _type_error_unary("^^", input1) } } diff --git a/internal/pkg/bifs/strings.go b/internal/pkg/bifs/strings.go index 53c3d32bce..3a8c006ada 100644 --- a/internal/pkg/bifs/strings.go +++ b/internal/pkg/bifs/strings.go @@ -13,7 +13,7 @@ import ( // ================================================================ func BIF_strlen(input1 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsStringOrVoid() { - return mlrval.ERROR + return _type_error_unary("strlen", input1) } else { return mlrval.FromInt(lib.UTF8Strlen(input1.AcquireStringValue())) } @@ -74,7 +74,7 @@ func BIF_substr_1_up(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.ABSENT } if input1.IsError() { - return mlrval.ERROR + return _type_error_unary("substr1", input1) } sinput := input1.String() @@ -106,7 +106,7 @@ func BIF_substr_0_up(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.ABSENT } if input1.IsError() { - return mlrval.ERROR + return _type_error_unary("substr0", input1) } sinput := input1.String() @@ -138,7 +138,7 @@ func BIF_index(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.ABSENT } if input1.IsError() { - return mlrval.ERROR + return _type_error_unary("index", input1) } sinput1 := input1.String() sinput2 := input2.String() @@ -176,13 +176,13 @@ func BIF_truncate(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return input2 } if !input1.IsStringOrVoid() { - return mlrval.ERROR + return _type_error_unary("truncate", input1) } if !input2.IsInt() { - return mlrval.ERROR + return _type_error_unary("truncate", input2) } if input2.AcquireIntValue() < 0 { - return mlrval.ERROR + return _type_error_unary("truncate", input2) } // Handle UTF-8 correctly: len(input1.AcquireStringValue()) will count bytes, not runes. @@ -209,7 +209,7 @@ func BIF_leftpad(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { } if !input2.IsInt() { - return mlrval.ERROR + return _type_error_unary("leftpad", input2) } inputString := input1.String() @@ -242,7 +242,7 @@ func BIF_rightpad(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { } if !input2.IsInt() { - return mlrval.ERROR + return _type_error_unary("rightpad", input2) } inputString := input1.String() @@ -357,7 +357,7 @@ func BIF_format(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval { } formatString, ok := mlrvals[0].GetStringValue() if !ok { // not a string - return mlrval.ERROR + return _type_error_unary("format", mlrvals[0]) } pieces := lib.SplitString(formatString, "{}") @@ -409,11 +409,11 @@ func BIF_unformatx(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { func bif_unformat_aux(input1, input2 *mlrval.Mlrval, inferTypes bool) *mlrval.Mlrval { template, ok1 := input1.GetStringValue() if !ok1 { - return mlrval.ERROR + return _type_error_unary("unformat", input1) } input, ok2 := input2.GetStringValue() if !ok2 { - return mlrval.ERROR + return _type_error_unary("unformat", input2) } templatePieces := strings.Split(template, "{}") @@ -470,7 +470,7 @@ func BIF_hexfmt(input1 *mlrval.Mlrval) *mlrval.Mlrval { // ---------------------------------------------------------------- func fmtnum_is(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsString() { - return mlrval.ERROR + return _type_error_unary("fmtnum", input2) } formatString := input2.AcquireStringValue() formatter, err := mlrval.GetFormatter(formatString) @@ -483,7 +483,7 @@ func fmtnum_is(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { func fmtnum_fs(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsString() { - return mlrval.ERROR + return _type_error_unary("fmtnum", input2) } formatString := input2.AcquireStringValue() formatter, err := mlrval.GetFormatter(formatString) @@ -496,7 +496,7 @@ func fmtnum_fs(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { func fmtnum_bs(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsString() { - return mlrval.ERROR + return _type_error_unary("fmtnum", input2) } formatString := input2.AcquireStringValue() formatter, err := mlrval.GetFormatter(formatString) From 5d3a78d84e39439b368eaca0a2d1f91805fecebc Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 29 Aug 2023 00:44:29 -0400 Subject: [PATCH 09/22] more --- internal/pkg/bifs/base.go | 28 +++++-- internal/pkg/bifs/stats.go | 106 +++++++++++++++++---------- internal/pkg/lib/logger.go | 12 ++- internal/pkg/mlrval/mlrval_output.go | 10 +++ 4 files changed, 109 insertions(+), 47 deletions(-) diff --git a/internal/pkg/bifs/base.go b/internal/pkg/bifs/base.go index 15e081f02f..f2975ffca0 100644 --- a/internal/pkg/bifs/base.go +++ b/internal/pkg/bifs/base.go @@ -97,10 +97,10 @@ type ComparatorFunc func(*mlrval.Mlrval, *mlrval.Mlrval) int func _type_error_unary(funcname string, input1 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromError( fmt.Errorf( - "%s: unacceptable type (%s) with value (%s)", + "%s: unacceptable type %s with value %s", funcname, input1.GetTypeName(), - input1.String(), + input1.StringMaybeQuoted(), ), ) } @@ -141,12 +141,12 @@ func _1u___(input1 *mlrval.Mlrval) *mlrval.Mlrval { func _type_error_binary(funcname string, input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromError( fmt.Errorf( - "%s: unacceptable types (%s, %s) with values (%s, %s)", + "%s: unacceptable types %s, %s with values %s, %s", funcname, input1.GetTypeName(), input2.GetTypeName(), - input1.String(), - input2.String(), + input1.StringMaybeQuoted(), + input2.StringMaybeQuoted(), ), ) } @@ -273,3 +273,21 @@ func recurseBinaryFuncOnInput1(binaryFunc BinaryFunc, input1, input2 *mlrval.Mlr return binaryFunc(input1, input2) } } + +func type_error_named_argument( + funcname string, + expected_type_name string, + varname string, + varval *mlrval.Mlrval, +) *mlrval.Mlrval { + return mlrval.FromError( + fmt.Errorf( + "%s: %s should be a %s; got type %s with value %s", + funcname, + varname, + expected_type_name, + varval.GetTypeName(), + varval.StringMaybeQuoted(), + ), + ) +} diff --git a/internal/pkg/bifs/stats.go b/internal/pkg/bifs/stats.go index 99e1e0ccd3..8d379bb625 100644 --- a/internal/pkg/bifs/stats.go +++ b/internal/pkg/bifs/stats.go @@ -156,7 +156,7 @@ func BIF_finalize_kurtosis(mn, msum, msum2, msum3, msum4 *mlrval.Mlrval) *mlrval // This is a helper function for BIFs which operate only on array or map. // It shorthands what values to return for non-collection inputs. -func check_collection(c *mlrval.Mlrval) (bool, *mlrval.Mlrval) { +func check_collection(c *mlrval.Mlrval, funcname string) (bool, *mlrval.Mlrval) { vtype := c.Type() switch vtype { case mlrval.MT_ARRAY: @@ -165,8 +165,10 @@ func check_collection(c *mlrval.Mlrval) (bool, *mlrval.Mlrval) { return true, c case mlrval.MT_ABSENT: return false, mlrval.ABSENT + case mlrval.MT_ERROR: + return false, c default: - return false, mlrval.ERROR + return false, _type_error_unary(funcname, c) } } @@ -186,7 +188,7 @@ func collection_sum_of_function( } func BIF_count(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "count") if !ok { return value_if_not } @@ -200,7 +202,7 @@ func BIF_count(collection *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_null_count(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "null_count") if !ok { return value_if_not } @@ -221,7 +223,7 @@ func BIF_null_count(collection *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_distinct_count(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "distinct_count") if !ok { return value_if_not } @@ -243,18 +245,19 @@ func BIF_distinct_count(collection *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_mode(collection *mlrval.Mlrval) *mlrval.Mlrval { - return bif_mode_or_antimode(collection, func(a, b int) bool { return a > b }) + return bif_mode_or_antimode(collection, "mode", func(a, b int) bool { return a > b }) } func BIF_antimode(collection *mlrval.Mlrval) *mlrval.Mlrval { - return bif_mode_or_antimode(collection, func(a, b int) bool { return a < b }) + return bif_mode_or_antimode(collection, "antimode", func(a, b int) bool { return a < b }) } func bif_mode_or_antimode( collection *mlrval.Mlrval, + funcname string, cmp func(int, int) bool, ) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, funcname) if !ok { return value_if_not } @@ -316,7 +319,7 @@ func bif_mode_or_antimode( } func BIF_sum(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "sum") if !ok { return value_if_not } @@ -329,7 +332,7 @@ func BIF_sum(collection *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_sum2(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "sum2") if !ok { return value_if_not } @@ -340,7 +343,7 @@ func BIF_sum2(collection *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_sum3(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "sum3") if !ok { return value_if_not } @@ -351,7 +354,7 @@ func BIF_sum3(collection *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_sum4(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "sum4") if !ok { return value_if_not } @@ -363,7 +366,7 @@ func BIF_sum4(collection *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_mean(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "mean") if !ok { return value_if_not } @@ -376,7 +379,7 @@ func BIF_mean(collection *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_meaneb(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "meaneb") if !ok { return value_if_not } @@ -387,7 +390,7 @@ func BIF_meaneb(collection *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_variance(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "variance") if !ok { return value_if_not } @@ -398,7 +401,7 @@ func BIF_variance(collection *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_stddev(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "stddev") if !ok { return value_if_not } @@ -409,7 +412,7 @@ func BIF_stddev(collection *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_skewness(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "skewness") if !ok { return value_if_not } @@ -421,7 +424,7 @@ func BIF_skewness(collection *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_kurtosis(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "kurtosis") if !ok { return value_if_not } @@ -434,7 +437,7 @@ func BIF_kurtosis(collection *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_minlen(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "minlen") if !ok { return value_if_not } @@ -446,7 +449,7 @@ func BIF_minlen(collection *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_maxlen(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "maxlen") if !ok { return value_if_not } @@ -458,7 +461,7 @@ func BIF_maxlen(collection *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_sort_collection(collection *mlrval.Mlrval) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + ok, value_if_not := check_collection(collection, "sort_collection") if !ok { return value_if_not } @@ -492,21 +495,21 @@ func BIF_sort_collection(collection *mlrval.Mlrval) *mlrval.Mlrval { func BIF_median( collection *mlrval.Mlrval, ) *mlrval.Mlrval { - return BIF_percentile(collection, mlrval.FromFloat(50.0)) + return bif_percentile_with_options_aux(collection, mlrval.FromFloat(50.0), nil, "median") } func BIF_median_with_options( collection *mlrval.Mlrval, options *mlrval.Mlrval, ) *mlrval.Mlrval { - return BIF_percentile_with_options(collection, mlrval.FromFloat(50.0), options) + return bif_percentile_with_options_aux(collection, mlrval.FromFloat(50.0), options, "median") } func BIF_percentile( collection *mlrval.Mlrval, percentile *mlrval.Mlrval, ) *mlrval.Mlrval { - return BIF_percentile_with_options(collection, percentile, nil) + return bif_percentile_with_options_aux(collection, percentile, nil, "percentile") } func BIF_percentile_with_options( @@ -514,16 +517,14 @@ func BIF_percentile_with_options( percentile *mlrval.Mlrval, options *mlrval.Mlrval, ) *mlrval.Mlrval { - percentiles := mlrval.FromSingletonArray(percentile) - outputs := BIF_percentiles_with_options(collection, percentiles, options) - return outputs.AcquireMapValue().Head.Value + return bif_percentile_with_options_aux(collection, percentile, options, "percentile") } func BIF_percentiles( collection *mlrval.Mlrval, percentiles *mlrval.Mlrval, ) *mlrval.Mlrval { - return BIF_percentiles_with_options(collection, percentiles, nil) + return bif_percentiles_with_options_aux(collection, percentiles, nil, "percentiles") } func BIF_percentiles_with_options( @@ -531,7 +532,34 @@ func BIF_percentiles_with_options( percentiles *mlrval.Mlrval, options *mlrval.Mlrval, ) *mlrval.Mlrval { - ok, value_if_not := check_collection(collection) + return bif_percentiles_with_options_aux(collection, percentiles, options, "percentiles") +} + +func bif_percentile_with_options_aux( + collection *mlrval.Mlrval, + percentile *mlrval.Mlrval, + options *mlrval.Mlrval, + funcname string, +) *mlrval.Mlrval { + percentiles := mlrval.FromSingletonArray(percentile) + outputs := bif_percentiles_with_options_aux(collection, percentiles, options, funcname) + + // Check for error/absent returns from the main impl body + ok, value_if_not := check_collection(outputs, funcname) + if !ok { + return value_if_not + } + + return outputs.AcquireMapValue().Head.Value +} + +func bif_percentiles_with_options_aux( + collection *mlrval.Mlrval, + percentiles *mlrval.Mlrval, + options *mlrval.Mlrval, + funcname string, +) *mlrval.Mlrval { + ok, value_if_not := check_collection(collection, funcname) if !ok { return value_if_not } @@ -543,7 +571,7 @@ func BIF_percentiles_with_options( if options != nil { om := options.GetMap() if om == nil { // not a map - return mlrval.ERROR + return type_error_named_argument(funcname, "map", "options", options) } for pe := om.Head; pe != nil; pe = pe.Next { if pe.Key == "array_is_sorted" || pe.Key == "ais" { @@ -552,7 +580,7 @@ func BIF_percentiles_with_options( } else if mlrval.Equals(pe.Value, mlrval.FALSE) { array_is_sorted = false } else { - return mlrval.ERROR + return type_error_named_argument(funcname, "boolean", pe.Key, pe.Value) } } else if pe.Key == "interpolate_linearly" || pe.Key == "il" { if mlrval.Equals(pe.Value, mlrval.TRUE) { @@ -560,7 +588,7 @@ func BIF_percentiles_with_options( } else if mlrval.Equals(pe.Value, mlrval.FALSE) { interpolate_linearly = false } else { - return mlrval.ERROR + return type_error_named_argument(funcname, "boolean", pe.Key, pe.Value) } } else if pe.Key == "output_array_not_map" || pe.Key == "oa" { if mlrval.Equals(pe.Value, mlrval.TRUE) { @@ -568,7 +596,7 @@ func BIF_percentiles_with_options( } else if mlrval.Equals(pe.Value, mlrval.FALSE) { output_array_not_map = false } else { - return mlrval.ERROR + return type_error_named_argument(funcname, "boolean", pe.Key, pe.Value) } } } @@ -577,31 +605,33 @@ func BIF_percentiles_with_options( var sorted_array *mlrval.Mlrval if array_is_sorted { if !collection.IsArray() { - return mlrval.ERROR + return type_error_named_argument(funcname, "array", "collection", collection) } sorted_array = collection } else { sorted_array = BIF_sort_collection(collection) } - return bif_percentiles( + return bif_percentiles_impl( sorted_array.AcquireArrayValue(), percentiles, interpolate_linearly, output_array_not_map, + funcname, ) } -func bif_percentiles( +func bif_percentiles_impl( sorted_array []*mlrval.Mlrval, percentiles *mlrval.Mlrval, interpolate_linearly bool, output_array_not_map bool, + funcname string, ) *mlrval.Mlrval { ps := percentiles.GetArray() if ps == nil { // not an array - return mlrval.ERROR + return type_error_named_argument(funcname, "array", "percentiles", percentiles) } outputs := make([]*mlrval.Mlrval, len(ps)) @@ -609,7 +639,7 @@ func bif_percentiles( for i, _ := range ps { p, ok := ps[i].GetNumericToFloatValue() if !ok { - outputs[i] = mlrval.ERROR.Copy() + outputs[i] = type_error_named_argument(funcname, "numeric", "percentile", ps[i]) } else if len(sorted_array) == 0 { outputs[i] = mlrval.VOID } else { diff --git a/internal/pkg/lib/logger.go b/internal/pkg/lib/logger.go index 31876cb915..5868dccf59 100644 --- a/internal/pkg/lib/logger.go +++ b/internal/pkg/lib/logger.go @@ -31,9 +31,11 @@ func InternalCodingErrorIf(condition bool) { "(unknown)", ) } - // Uncomment this and re-run if you want to get a stack trace to get the + // Use this and re-run if you want to get a stack trace to get the // call-tree that led to the indicated file/line: - // panic("eek") + if os.Getenv("MLR_PANIC_ON_INTERNAL_ERROR") != "" { + panic("Here is the stack trace") + } os.Exit(1) } @@ -61,9 +63,11 @@ func InternalCodingErrorWithMessageIf(condition bool, message string) { message, ) } - // Uncomment this and re-run if you want to get a stack trace to get the + // use this and re-run if you want to get a stack trace to get the // call-tree that led to the indicated file/line: - // panic("eek") + if os.Getenv("MLR_PANIC_ON_INTERNAL_ERROR") != "" { + panic("Here is the stack trace") + } os.Exit(1) } diff --git a/internal/pkg/mlrval/mlrval_output.go b/internal/pkg/mlrval/mlrval_output.go index 7b354b359a..d864806b3c 100644 --- a/internal/pkg/mlrval/mlrval_output.go +++ b/internal/pkg/mlrval/mlrval_output.go @@ -44,6 +44,16 @@ func (mv *Mlrval) OriginalString() string { } } +// StringMaybeQuoted Returns strings double-quoted; all else not. +func (mv *Mlrval) StringMaybeQuoted() string { + output := mv.String() + if mv.mvtype == MT_VOID || mv.mvtype == MT_STRING { + return `"` + output + `"` + } else { + return output + } +} + // See mlrval.go for more about JIT-formatting of string backings func (mv *Mlrval) setPrintRep() { if !mv.printrepValid { From 5a7622fe702c930a84159792860b8c51761f4cec Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 29 Aug 2023 00:51:38 -0400 Subject: [PATCH 10/22] more --- internal/pkg/bifs/base.go | 2 +- internal/pkg/bifs/mathlib.go | 110 +++++++++++++++++++++++------------ xtodo.txt | 2 + 3 files changed, 75 insertions(+), 39 deletions(-) diff --git a/internal/pkg/bifs/base.go b/internal/pkg/bifs/base.go index f2975ffca0..54de8d56eb 100644 --- a/internal/pkg/bifs/base.go +++ b/internal/pkg/bifs/base.go @@ -72,7 +72,7 @@ type RegexCaptureBinaryFunc func(input *mlrval.Mlrval, sregex *mlrval.Mlrval) (* // Helps keystroke-saving for wrapping Go math-library functions // Examples: cos, sin, etc. type mathLibUnaryFunc func(float64) float64 -type mathLibUnaryFuncWrapper func(input1 *mlrval.Mlrval, f mathLibUnaryFunc) *mlrval.Mlrval +type mathLibUnaryFuncWrapper func(input1 *mlrval.Mlrval, f mathLibUnaryFunc, fname string) *mlrval.Mlrval // Function-pointer type for binary-operator disposition matrices. type BinaryFunc func(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval diff --git a/internal/pkg/bifs/mathlib.go b/internal/pkg/bifs/mathlib.go index 3f2b290863..6aff409518 100644 --- a/internal/pkg/bifs/mathlib.go +++ b/internal/pkg/bifs/mathlib.go @@ -13,33 +13,33 @@ import ( // ---------------------------------------------------------------- // Return error (unary math-library func) -func _math_unary_erro1(input1 *mlrval.Mlrval, f mathLibUnaryFunc) *mlrval.Mlrval { - return mlrval.ERROR +func _math_unary_erro1(input1 *mlrval.Mlrval, f mathLibUnaryFunc, fname string) *mlrval.Mlrval { + return _type_error_unary(fname, input1) } // Return absent (unary math-library func) -func _math_unary_absn1(input1 *mlrval.Mlrval, f mathLibUnaryFunc) *mlrval.Mlrval { +func _math_unary_absn1(input1 *mlrval.Mlrval, f mathLibUnaryFunc, fname string) *mlrval.Mlrval { return mlrval.ABSENT } // Return null (unary math-library func) -func _math_unary_null1(input1 *mlrval.Mlrval, f mathLibUnaryFunc) *mlrval.Mlrval { +func _math_unary_null1(input1 *mlrval.Mlrval, f mathLibUnaryFunc, fname string) *mlrval.Mlrval { return mlrval.NULL } // Return void (unary math-library func) -func _math_unary_void1(input1 *mlrval.Mlrval, f mathLibUnaryFunc) *mlrval.Mlrval { +func _math_unary_void1(input1 *mlrval.Mlrval, f mathLibUnaryFunc, fname string) *mlrval.Mlrval { return mlrval.VOID } // ---------------------------------------------------------------- -func math_unary_f_i(input1 *mlrval.Mlrval, f mathLibUnaryFunc) *mlrval.Mlrval { +func math_unary_f_i(input1 *mlrval.Mlrval, f mathLibUnaryFunc, fname string) *mlrval.Mlrval { return mlrval.FromFloat(f(float64(input1.AcquireIntValue()))) } -func math_unary_i_i(input1 *mlrval.Mlrval, f mathLibUnaryFunc) *mlrval.Mlrval { +func math_unary_i_i(input1 *mlrval.Mlrval, f mathLibUnaryFunc, fname string) *mlrval.Mlrval { return mlrval.FromInt(int64(f(float64(input1.AcquireIntValue())))) } -func math_unary_f_f(input1 *mlrval.Mlrval, f mathLibUnaryFunc) *mlrval.Mlrval { +func math_unary_f_f(input1 *mlrval.Mlrval, f mathLibUnaryFunc, fname string) *mlrval.Mlrval { return mlrval.FromFloat(f(input1.AcquireFloatValue())) } @@ -58,45 +58,75 @@ var mudispo = [mlrval.MT_DIM]mathLibUnaryFuncWrapper{ /*ABSENT */ _math_unary_absn1, } -func BIF_acos(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mudispo[input1.Type()](input1, math.Acos) } +func BIF_acos(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mudispo[input1.Type()](input1, math.Acos, "acos") +} func BIF_acosh(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return mudispo[input1.Type()](input1, math.Acosh) + return mudispo[input1.Type()](input1, math.Acosh, "acosh") +} +func BIF_asin(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mudispo[input1.Type()](input1, math.Asin, "asin") } -func BIF_asin(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mudispo[input1.Type()](input1, math.Asin) } func BIF_asinh(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return mudispo[input1.Type()](input1, math.Asinh) + return mudispo[input1.Type()](input1, math.Asinh, "asinh") +} +func BIF_atan(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mudispo[input1.Type()](input1, math.Atan, "atan") } -func BIF_atan(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mudispo[input1.Type()](input1, math.Atan) } func BIF_atanh(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return mudispo[input1.Type()](input1, math.Atanh) -} -func BIF_cbrt(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mudispo[input1.Type()](input1, math.Cbrt) } -func BIF_cos(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mudispo[input1.Type()](input1, math.Cos) } -func BIF_cosh(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mudispo[input1.Type()](input1, math.Cosh) } -func BIF_erf(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mudispo[input1.Type()](input1, math.Erf) } -func BIF_erfc(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mudispo[input1.Type()](input1, math.Erfc) } -func BIF_exp(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mudispo[input1.Type()](input1, math.Exp) } + return mudispo[input1.Type()](input1, math.Atanh, "atanh") +} +func BIF_cbrt(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mudispo[input1.Type()](input1, math.Cbrt, "atan") +} +func BIF_cos(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mudispo[input1.Type()](input1, math.Cos, "cos") +} +func BIF_cosh(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mudispo[input1.Type()](input1, math.Cosh, "cosh") +} +func BIF_erf(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mudispo[input1.Type()](input1, math.Erf, "erf") +} +func BIF_erfc(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mudispo[input1.Type()](input1, math.Erfc, "erfc") +} +func BIF_exp(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mudispo[input1.Type()](input1, math.Exp, "exp") +} func BIF_expm1(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return mudispo[input1.Type()](input1, math.Expm1) + return mudispo[input1.Type()](input1, math.Expm1, "expm1") } func BIF_invqnorm(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return mudispo[input1.Type()](input1, lib.Invqnorm) + return mudispo[input1.Type()](input1, lib.Invqnorm, "invqnorm") +} +func BIF_log(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mudispo[input1.Type()](input1, math.Log, "log") } -func BIF_log(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mudispo[input1.Type()](input1, math.Log) } func BIF_log10(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return mudispo[input1.Type()](input1, math.Log10) + return mudispo[input1.Type()](input1, math.Log10, "log10") } func BIF_log1p(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return mudispo[input1.Type()](input1, math.Log1p) + return mudispo[input1.Type()](input1, math.Log1p, "log1p") } func BIF_qnorm(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return mudispo[input1.Type()](input1, lib.Qnorm) + return mudispo[input1.Type()](input1, lib.Qnorm, "qnorm") +} +func BIF_sin(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mudispo[input1.Type()](input1, math.Sin, "sin") +} +func BIF_sinh(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mudispo[input1.Type()](input1, math.Sinh, "sinh") +} +func BIF_sqrt(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mudispo[input1.Type()](input1, math.Sqrt, "sqrt") +} +func BIF_tan(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mudispo[input1.Type()](input1, math.Tan, "tan") +} +func BIF_tanh(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return mudispo[input1.Type()](input1, math.Tanh, "tanh") } -func BIF_sin(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mudispo[input1.Type()](input1, math.Sin) } -func BIF_sinh(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mudispo[input1.Type()](input1, math.Sinh) } -func BIF_sqrt(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mudispo[input1.Type()](input1, math.Sqrt) } -func BIF_tan(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mudispo[input1.Type()](input1, math.Tan) } -func BIF_tanh(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mudispo[input1.Type()](input1, math.Tanh) } // Disposition vector for unary mathlib functions which are int-preserving var imudispo = [mlrval.MT_DIM]mathLibUnaryFuncWrapper{ @@ -114,17 +144,21 @@ var imudispo = [mlrval.MT_DIM]mathLibUnaryFuncWrapper{ } // Int-preserving -func BIF_abs(input1 *mlrval.Mlrval) *mlrval.Mlrval { return imudispo[input1.Type()](input1, math.Abs) } // xxx +func BIF_abs(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return imudispo[input1.Type()](input1, math.Abs, "abs") +} // xxx func BIF_ceil(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return imudispo[input1.Type()](input1, math.Ceil) + return imudispo[input1.Type()](input1, math.Ceil, "ceil") } // xxx func BIF_floor(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return imudispo[input1.Type()](input1, math.Floor) + return imudispo[input1.Type()](input1, math.Floor, "floor") } // xxx func BIF_round(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return imudispo[input1.Type()](input1, math.Round) -} // xxx -func BIF_sgn(input1 *mlrval.Mlrval) *mlrval.Mlrval { return imudispo[input1.Type()](input1, lib.Sgn) } // xxx + return imudispo[input1.Type()](input1, math.Round, "round") +} // xxx +func BIF_sgn(input1 *mlrval.Mlrval) *mlrval.Mlrval { + return imudispo[input1.Type()](input1, lib.Sgn, "sgn") +} // xxx // ================================================================ // Exponentiation: DSL operator '**'. See also diff --git a/xtodo.txt b/xtodo.txt index 35e0a85dcd..1bf03a171f 100644 --- a/xtodo.txt +++ b/xtodo.txt @@ -3,3 +3,5 @@ * optional env var: MLR_DATA_ERROR_FAIL_FAST or somesuch * maybe call it data-processing error to differentiate from input-data error -- ? * look at: mr -vvv test/cases/io-spec-tsv/0004/cmd + +grep -c mlrval.ERROR $(rg -wl mlrval.ERROR|sort) From 0b0fd85cca762bb7cb7620db16875f4d8a4ebc6d Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 29 Aug 2023 07:47:10 -0400 Subject: [PATCH 11/22] more --- internal/pkg/bifs/arithmetic.go | 62 ++++++++++++++++---------------- internal/pkg/bifs/base.go | 21 +++++++++-- internal/pkg/bifs/bits.go | 16 ++++----- internal/pkg/bifs/booleans.go | 8 ++--- internal/pkg/bifs/cmp.go | 14 ++++---- internal/pkg/bifs/collections.go | 4 +-- internal/pkg/bifs/mathlib.go | 10 +++--- internal/pkg/bifs/stats.go | 2 +- internal/pkg/bifs/strings.go | 34 +++++++++--------- internal/pkg/bifs/types.go | 10 +++--- 10 files changed, 99 insertions(+), 82 deletions(-) diff --git a/internal/pkg/bifs/arithmetic.go b/internal/pkg/bifs/arithmetic.go index 2213422186..8d6e15b89b 100644 --- a/internal/pkg/bifs/arithmetic.go +++ b/internal/pkg/bifs/arithmetic.go @@ -11,7 +11,7 @@ import ( // Unary plus operator func upos_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_unary("+", input1) + return type_error_unary("+", input1) } var upos_dispositions = [mlrval.MT_DIM]UnaryFunc{ @@ -36,7 +36,7 @@ func BIF_plus_unary(input1 *mlrval.Mlrval) *mlrval.Mlrval { // Unary minus operator func uneg_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_unary("-", input1) + return type_error_unary("-", input1) } func uneg_i_i(input1 *mlrval.Mlrval) *mlrval.Mlrval { @@ -105,7 +105,7 @@ func plus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func plste(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("+", input1, input2) + return type_error_binary("+", input1, input2) } var plus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -167,7 +167,7 @@ func minus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func mnste(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("-", input1, input2) + return type_error_binary("-", input1, input2) } var minus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -245,7 +245,7 @@ func times_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func tmste(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("*", input1, input2) + return type_error_binary("*", input1, input2) } var times_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -312,7 +312,7 @@ func divide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func dvdte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("/", input1, input2) + return type_error_binary("/", input1, input2) } var divide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -377,7 +377,7 @@ func int_divide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func idvte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("//", input1, input2) + return type_error_binary("//", input1, input2) } var int_divide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -417,7 +417,7 @@ func dotplus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func dplte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary(".+", input1, input2) + return type_error_binary(".+", input1, input2) } var dot_plus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -457,7 +457,7 @@ func dotminus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func dmnte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary(".-", input1, input2) + return type_error_binary(".-", input1, input2) } var dotminus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -497,7 +497,7 @@ func dottimes_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func dttte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary(".*", input1, input2) + return type_error_binary(".*", input1, input2) } var dottimes_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -537,7 +537,7 @@ func dotdivide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func ddvte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("./", input1, input2) + return type_error_binary("./", input1, input2) } var dotdivide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -602,7 +602,7 @@ func dotidivide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func didte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary(".//", input1, input2) + return type_error_binary(".//", input1, input2) } var dotidivide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -670,7 +670,7 @@ func modulus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func modte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("%", input1, input2) + return type_error_binary("%", input1, input2) } var modulus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -737,7 +737,7 @@ func imodexp(a, e, m int64) int64 { return c } -func imodop(input1, input2, input3 *mlrval.Mlrval, iop i_iii_func) *mlrval.Mlrval { +func imodop(input1, input2, input3 *mlrval.Mlrval, iop i_iii_func, funcname string) *mlrval.Mlrval { if !input1.IsLegit() { return input1 } @@ -747,29 +747,29 @@ func imodop(input1, input2, input3 *mlrval.Mlrval, iop i_iii_func) *mlrval.Mlrva if !input3.IsLegit() { return input3 } - if !input1.IsInt() { - return mlrval.ERROR - } - if !input2.IsInt() { - return mlrval.ERROR - } - if !input3.IsInt() { - return mlrval.ERROR + if !input1.IsInt() || !input2.IsInt() || !input3.IsInt() { + return type_error_ternary(funcname, input1, input2, input3) } - return mlrval.FromInt(iop(input1.AcquireIntValue(), input2.AcquireIntValue(), input3.AcquireIntValue())) + return mlrval.FromInt( + iop( + input1.AcquireIntValue(), + input2.AcquireIntValue(), + input3.AcquireIntValue(), + ), + ) } func BIF_mod_add(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { - return imodop(input1, input2, input3, imodadd) + return imodop(input1, input2, input3, imodadd, "madd") } func BIF_mod_sub(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { - return imodop(input1, input2, input3, imodsub) + return imodop(input1, input2, input3, imodsub, "msub") } func BIF_mod_mul(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { - return imodop(input1, input2, input3, imodmul) + return imodop(input1, input2, input3, imodmul, "mmul") } func BIF_mod_exp(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { @@ -777,7 +777,7 @@ func BIF_mod_exp(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { if input2.IsInt() && input2.AcquireIntValue() < 0 { return mlrval.ERROR } - return imodop(input1, input2, input3, imodexp) + return imodop(input1, input2, input3, imodexp, "mexp") } // ================================================================ @@ -846,7 +846,7 @@ func min_s_ss(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func min_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("min", input1, input2) + return type_error_binary("min", input1, input2) } var min_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -910,7 +910,7 @@ func bif_min_unary_map(input1 *mlrval.Mlrval) *mlrval.Mlrval { var min_unary_dispositions = [mlrval.MT_DIM]UnaryFunc{} func min_unary_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_unary("min", input1) + return type_error_unary("min", input1) } func init() { @@ -1016,7 +1016,7 @@ func max_s_ss(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func max_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("max", input1, input2) + return type_error_binary("max", input1, input2) } var max_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -1080,7 +1080,7 @@ func bif_max_unary_map(input1 *mlrval.Mlrval) *mlrval.Mlrval { var max_unary_dispositions = [mlrval.MT_DIM]UnaryFunc{} func max_unary_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_unary("max", input1) + return type_error_unary("max", input1) } func init() { diff --git a/internal/pkg/bifs/base.go b/internal/pkg/bifs/base.go index 54de8d56eb..dba349c783 100644 --- a/internal/pkg/bifs/base.go +++ b/internal/pkg/bifs/base.go @@ -94,7 +94,7 @@ type ComparatorFunc func(*mlrval.Mlrval, *mlrval.Mlrval) int // ---------------------------------------------------------------- // Type error for unary functions -func _type_error_unary(funcname string, input1 *mlrval.Mlrval) *mlrval.Mlrval { +func type_error_unary(funcname string, input1 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromError( fmt.Errorf( "%s: unacceptable type %s with value %s", @@ -138,7 +138,7 @@ func _1u___(input1 *mlrval.Mlrval) *mlrval.Mlrval { // ---------------------------------------------------------------- // Type error for binary functions -func _type_error_binary(funcname string, input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { +func type_error_binary(funcname string, input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromError( fmt.Errorf( "%s: unacceptable types %s, %s with values %s, %s", @@ -291,3 +291,20 @@ func type_error_named_argument( ), ) } + +// ---------------------------------------------------------------- +// Type error for ternary functions +func type_error_ternary(funcname string, input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { + return mlrval.FromError( + fmt.Errorf( + "%s: unacceptable types %s, %s, %s with values %s, %s, %s", + funcname, + input1.GetTypeName(), + input2.GetTypeName(), + input3.GetTypeName(), + input1.StringMaybeQuoted(), + input2.StringMaybeQuoted(), + input3.StringMaybeQuoted(), + ), + ) +} diff --git a/internal/pkg/bifs/bits.go b/internal/pkg/bifs/bits.go index e10d6e9b3e..93e0eea15b 100644 --- a/internal/pkg/bifs/bits.go +++ b/internal/pkg/bifs/bits.go @@ -12,7 +12,7 @@ func bitwise_not_i_i(input1 *mlrval.Mlrval) *mlrval.Mlrval { } func bitwise_not_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_unary("~", input1) + return type_error_unary("~", input1) } var bitwise_not_dispositions = [mlrval.MT_DIM]UnaryFunc{ @@ -56,7 +56,7 @@ func bitcount_i_i(input1 *mlrval.Mlrval) *mlrval.Mlrval { } func bitcount_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_unary("bitcount", input1) + return type_error_unary("bitcount", input1) } var bitcount_dispositions = [mlrval.MT_DIM]UnaryFunc{ @@ -85,7 +85,7 @@ func bitwise_and_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func bwandte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("&", input1, input2) + return type_error_binary("&", input1, input2) } var bitwise_and_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -115,7 +115,7 @@ func bitwise_or_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func bworte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("|", input1, input2) + return type_error_binary("|", input1, input2) } var bitwise_or_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -145,7 +145,7 @@ func bitwise_xor_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func bwxorte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("^", input1, input2) + return type_error_binary("^", input1, input2) } var bitwise_xor_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -175,7 +175,7 @@ func lsh_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func lshfte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("<<", input1, input2) + return type_error_binary("<<", input1, input2) } var left_shift_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -205,7 +205,7 @@ func srsh_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func srste(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary(">>>", input1, input2) + return type_error_binary(">>>", input1, input2) } var signed_right_shift_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -238,7 +238,7 @@ func ursh_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func rste(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary(">>", input1, input2) + return type_error_binary(">>", input1, input2) } var unsigned_right_shift_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ diff --git a/internal/pkg/bifs/booleans.go b/internal/pkg/bifs/booleans.go index b51a967bce..0364e7a360 100644 --- a/internal/pkg/bifs/booleans.go +++ b/internal/pkg/bifs/booleans.go @@ -12,7 +12,7 @@ func BIF_logical_NOT(input1 *mlrval.Mlrval) *mlrval.Mlrval { if input1.IsBool() { return mlrval.FromBool(!input1.AcquireBoolValue()) } else { - return _type_error_unary("!", input1) + return type_error_unary("!", input1) } } @@ -20,7 +20,7 @@ func BIF_logical_AND(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if input1.IsBool() && input2.IsBool() { return mlrval.FromBool(input1.AcquireBoolValue() && input2.AcquireBoolValue()) } else { - return _type_error_unary("&&", input1) + return type_error_unary("&&", input1) } } @@ -28,7 +28,7 @@ func BIF_logical_OR(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if input1.IsBool() && input2.IsBool() { return mlrval.FromBool(input1.AcquireBoolValue() || input2.AcquireBoolValue()) } else { - return _type_error_unary("||", input1) + return type_error_unary("||", input1) } } @@ -36,6 +36,6 @@ func BIF_logical_XOR(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if input1.IsBool() && input2.IsBool() { return mlrval.FromBool(input1.AcquireBoolValue() != input2.AcquireBoolValue()) } else { - return _type_error_unary("^^", input1) + return type_error_unary("^^", input1) } } diff --git a/internal/pkg/bifs/cmp.go b/internal/pkg/bifs/cmp.go index a98470cd36..670a3e7ba1 100644 --- a/internal/pkg/bifs/cmp.go +++ b/internal/pkg/bifs/cmp.go @@ -271,7 +271,7 @@ func ne_b_mm(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { var eq_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{} func eqte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("==", input1, input2) + return type_error_binary("==", input1, input2) } func init() { @@ -292,7 +292,7 @@ func init() { } func nete(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("!=", input1, input2) + return type_error_binary("!=", input1, input2) } var ne_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -311,7 +311,7 @@ var ne_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ } func gtte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary(">", input1, input2) + return type_error_binary(">", input1, input2) } var gt_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -330,7 +330,7 @@ var gt_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ } func gete(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary(">=", input1, input2) + return type_error_binary(">=", input1, input2) } var ge_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -349,7 +349,7 @@ var ge_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ } func ltte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("<", input1, input2) + return type_error_binary("<", input1, input2) } var lt_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -368,7 +368,7 @@ var lt_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ } func lete(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("<=", input1, input2) + return type_error_binary("<=", input1, input2) } var le_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -387,7 +387,7 @@ var le_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ } func cmpte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("<=>", input1, input2) + return type_error_binary("<=>", input1, input2) } var cmp_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ diff --git a/internal/pkg/bifs/collections.go b/internal/pkg/bifs/collections.go index db2e03857d..34e0da1bb2 100644 --- a/internal/pkg/bifs/collections.go +++ b/internal/pkg/bifs/collections.go @@ -66,7 +66,7 @@ func depth_from_scalar(input1 *mlrval.Mlrval) *mlrval.Mlrval { var depth_dispositions = [mlrval.MT_DIM]UnaryFunc{} func depth_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_unary("depth", input1) + return type_error_unary("depth", input1) } func init() { @@ -139,7 +139,7 @@ func leafcount_from_scalar(input1 *mlrval.Mlrval) *mlrval.Mlrval { } func leafcount_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_unary("leafcount", input1) + return type_error_unary("leafcount", input1) } var leafcount_dispositions = [mlrval.MT_DIM]UnaryFunc{ diff --git a/internal/pkg/bifs/mathlib.go b/internal/pkg/bifs/mathlib.go index 6aff409518..79ea45e552 100644 --- a/internal/pkg/bifs/mathlib.go +++ b/internal/pkg/bifs/mathlib.go @@ -14,7 +14,7 @@ import ( // ---------------------------------------------------------------- // Return error (unary math-library func) func _math_unary_erro1(input1 *mlrval.Mlrval, f mathLibUnaryFunc, fname string) *mlrval.Mlrval { - return _type_error_unary(fname, input1) + return type_error_unary(fname, input1) } // Return absent (unary math-library func) @@ -185,7 +185,7 @@ func pow_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func powte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("**", input1, input2) + return type_error_binary("**", input1, input2) } var pow_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -222,7 +222,7 @@ func atan2_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func atan2te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("atan2", input1, input2) + return type_error_binary("atan2", input1, input2) } var atan2_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -263,7 +263,7 @@ func roundm_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func rdmte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("roundm", input1, input2) + return type_error_binary("roundm", input1, input2) } var roundm_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -287,7 +287,7 @@ func BIF_roundm(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { // ================================================================ func logifit_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("logifit", input1, input2) + return type_error_binary("logifit", input1, input2) } func BIF_logifit(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { diff --git a/internal/pkg/bifs/stats.go b/internal/pkg/bifs/stats.go index 8d379bb625..6799b8fa53 100644 --- a/internal/pkg/bifs/stats.go +++ b/internal/pkg/bifs/stats.go @@ -168,7 +168,7 @@ func check_collection(c *mlrval.Mlrval, funcname string) (bool, *mlrval.Mlrval) case mlrval.MT_ERROR: return false, c default: - return false, _type_error_unary(funcname, c) + return false, type_error_unary(funcname, c) } } diff --git a/internal/pkg/bifs/strings.go b/internal/pkg/bifs/strings.go index 3a8c006ada..d7d885281e 100644 --- a/internal/pkg/bifs/strings.go +++ b/internal/pkg/bifs/strings.go @@ -13,7 +13,7 @@ import ( // ================================================================ func BIF_strlen(input1 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsStringOrVoid() { - return _type_error_unary("strlen", input1) + return type_error_unary("strlen", input1) } else { return mlrval.FromInt(lib.UTF8Strlen(input1.AcquireStringValue())) } @@ -43,7 +43,7 @@ func dot_s_xx(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func dot_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary(".", input1, input2) + return type_error_binary(".", input1, input2) } var dot_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -74,7 +74,7 @@ func BIF_substr_1_up(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.ABSENT } if input1.IsError() { - return _type_error_unary("substr1", input1) + return type_error_unary("substr1", input1) } sinput := input1.String() @@ -106,7 +106,7 @@ func BIF_substr_0_up(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.ABSENT } if input1.IsError() { - return _type_error_unary("substr0", input1) + return type_error_unary("substr0", input1) } sinput := input1.String() @@ -138,7 +138,7 @@ func BIF_index(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.ABSENT } if input1.IsError() { - return _type_error_unary("index", input1) + return type_error_unary("index", input1) } sinput1 := input1.String() sinput2 := input2.String() @@ -176,13 +176,13 @@ func BIF_truncate(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return input2 } if !input1.IsStringOrVoid() { - return _type_error_unary("truncate", input1) + return type_error_unary("truncate", input1) } if !input2.IsInt() { - return _type_error_unary("truncate", input2) + return type_error_unary("truncate", input2) } if input2.AcquireIntValue() < 0 { - return _type_error_unary("truncate", input2) + return type_error_unary("truncate", input2) } // Handle UTF-8 correctly: len(input1.AcquireStringValue()) will count bytes, not runes. @@ -209,7 +209,7 @@ func BIF_leftpad(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { } if !input2.IsInt() { - return _type_error_unary("leftpad", input2) + return type_error_unary("leftpad", input2) } inputString := input1.String() @@ -242,7 +242,7 @@ func BIF_rightpad(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { } if !input2.IsInt() { - return _type_error_unary("rightpad", input2) + return type_error_unary("rightpad", input2) } inputString := input1.String() @@ -357,7 +357,7 @@ func BIF_format(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval { } formatString, ok := mlrvals[0].GetStringValue() if !ok { // not a string - return _type_error_unary("format", mlrvals[0]) + return type_error_unary("format", mlrvals[0]) } pieces := lib.SplitString(formatString, "{}") @@ -409,11 +409,11 @@ func BIF_unformatx(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { func bif_unformat_aux(input1, input2 *mlrval.Mlrval, inferTypes bool) *mlrval.Mlrval { template, ok1 := input1.GetStringValue() if !ok1 { - return _type_error_unary("unformat", input1) + return type_error_unary("unformat", input1) } input, ok2 := input2.GetStringValue() if !ok2 { - return _type_error_unary("unformat", input2) + return type_error_unary("unformat", input2) } templatePieces := strings.Split(template, "{}") @@ -470,7 +470,7 @@ func BIF_hexfmt(input1 *mlrval.Mlrval) *mlrval.Mlrval { // ---------------------------------------------------------------- func fmtnum_is(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsString() { - return _type_error_unary("fmtnum", input2) + return type_error_unary("fmtnum", input2) } formatString := input2.AcquireStringValue() formatter, err := mlrval.GetFormatter(formatString) @@ -483,7 +483,7 @@ func fmtnum_is(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { func fmtnum_fs(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsString() { - return _type_error_unary("fmtnum", input2) + return type_error_unary("fmtnum", input2) } formatString := input2.AcquireStringValue() formatter, err := mlrval.GetFormatter(formatString) @@ -496,7 +496,7 @@ func fmtnum_fs(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { func fmtnum_bs(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsString() { - return _type_error_unary("fmtnum", input2) + return type_error_unary("fmtnum", input2) } formatString := input2.AcquireStringValue() formatter, err := mlrval.GetFormatter(formatString) @@ -510,7 +510,7 @@ func fmtnum_bs(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func fmtnum_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("fmtnum", input1, input2) + return type_error_binary("fmtnum", input1, input2) } var fmtnum_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ diff --git a/internal/pkg/bifs/types.go b/internal/pkg/bifs/types.go index 200f6b6100..c1c63819c8 100644 --- a/internal/pkg/bifs/types.go +++ b/internal/pkg/bifs/types.go @@ -38,7 +38,7 @@ func bool_to_int(input1 *mlrval.Mlrval) *mlrval.Mlrval { } func to_int_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_unary("int", input1) + return type_error_unary("int", input1) } var to_int_dispositions = [mlrval.MT_DIM]UnaryFunc{ @@ -86,7 +86,7 @@ func bool_to_int_with_base(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func to_int_with_base_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_binary("int", input1, input2) + return type_error_binary("int", input1, input2) } var to_int_with_base_dispositions = [mlrval.MT_DIM]BinaryFunc{ @@ -105,7 +105,7 @@ var to_int_with_base_dispositions = [mlrval.MT_DIM]BinaryFunc{ func BIF_int_with_base(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsInt() { - return _type_error_binary("int", input1, input2) + return type_error_binary("int", input1, input2) } return to_int_with_base_dispositions[input1.Type()](input1, input2) } @@ -133,7 +133,7 @@ func bool_to_float(input1 *mlrval.Mlrval) *mlrval.Mlrval { } func to_float_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_unary("float", input1) + return type_error_unary("float", input1) } var to_float_dispositions = [mlrval.MT_DIM]UnaryFunc{ @@ -173,7 +173,7 @@ func float_to_bool(input1 *mlrval.Mlrval) *mlrval.Mlrval { } func to_boolean_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return _type_error_unary("boolean", input1) + return type_error_unary("boolean", input1) } var to_boolean_dispositions = [mlrval.MT_DIM]UnaryFunc{ From 5ce38b0abe634786eaabc3f03bdb0efb80626757 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 29 Aug 2023 08:47:26 -0400 Subject: [PATCH 12/22] more --- internal/pkg/bifs/arithmetic.go | 46 ++++++------ internal/pkg/bifs/base.go | 45 ------------ internal/pkg/bifs/bits.go | 16 ++--- internal/pkg/bifs/booleans.go | 8 +-- internal/pkg/bifs/cmp.go | 14 ++-- internal/pkg/bifs/collections.go | 4 +- internal/pkg/bifs/mathlib.go | 10 +-- internal/pkg/bifs/stats.go | 2 +- internal/pkg/bifs/stats_test.go | 2 +- internal/pkg/bifs/strings.go | 34 ++++----- internal/pkg/bifs/types.go | 46 +++++++++--- internal/pkg/dsl/cst/env.go | 2 +- internal/pkg/mlrval/mlrval_new.go | 59 +++++++++++++++ internal/pkg/terminals/help/entry.go | 2 +- internal/pkg/transformers/fraction.go | 7 +- .../transformers/utils/percentile_keeper.go | 4 +- test/cases/io-spec-tsv/0004/expout | 8 +++ xtodo.txt | 71 +++++++++++++++++++ 18 files changed, 257 insertions(+), 123 deletions(-) diff --git a/internal/pkg/bifs/arithmetic.go b/internal/pkg/bifs/arithmetic.go index 8d6e15b89b..7728270ec7 100644 --- a/internal/pkg/bifs/arithmetic.go +++ b/internal/pkg/bifs/arithmetic.go @@ -1,6 +1,7 @@ package bifs import ( + "fmt" "math" "github.com/johnkerl/miller/internal/pkg/lib" @@ -11,7 +12,7 @@ import ( // Unary plus operator func upos_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_unary("+", input1) + return mlrval.FromTypeErrorUnary("+", input1) } var upos_dispositions = [mlrval.MT_DIM]UnaryFunc{ @@ -36,7 +37,7 @@ func BIF_plus_unary(input1 *mlrval.Mlrval) *mlrval.Mlrval { // Unary minus operator func uneg_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_unary("-", input1) + return mlrval.FromTypeErrorUnary("-", input1) } func uneg_i_i(input1 *mlrval.Mlrval) *mlrval.Mlrval { @@ -105,7 +106,7 @@ func plus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func plste(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("+", input1, input2) + return mlrval.FromTypeErrorBinary("+", input1, input2) } var plus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -167,7 +168,7 @@ func minus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func mnste(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("-", input1, input2) + return mlrval.FromTypeErrorBinary("-", input1, input2) } var minus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -245,7 +246,7 @@ func times_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func tmste(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("*", input1, input2) + return mlrval.FromTypeErrorBinary("*", input1, input2) } var times_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -312,7 +313,7 @@ func divide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func dvdte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("/", input1, input2) + return mlrval.FromTypeErrorBinary("/", input1, input2) } var divide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -377,7 +378,7 @@ func int_divide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func idvte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("//", input1, input2) + return mlrval.FromTypeErrorBinary("//", input1, input2) } var int_divide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -417,7 +418,7 @@ func dotplus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func dplte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary(".+", input1, input2) + return mlrval.FromTypeErrorBinary(".+", input1, input2) } var dot_plus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -457,7 +458,7 @@ func dotminus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func dmnte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary(".-", input1, input2) + return mlrval.FromTypeErrorBinary(".-", input1, input2) } var dotminus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -497,7 +498,7 @@ func dottimes_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func dttte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary(".*", input1, input2) + return mlrval.FromTypeErrorBinary(".*", input1, input2) } var dottimes_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -537,7 +538,7 @@ func dotdivide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func ddvte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("./", input1, input2) + return mlrval.FromTypeErrorBinary("./", input1, input2) } var dotdivide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -602,7 +603,7 @@ func dotidivide_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func didte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary(".//", input1, input2) + return mlrval.FromTypeErrorBinary(".//", input1, input2) } var dotidivide_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -670,7 +671,7 @@ func modulus_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func modte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("%", input1, input2) + return mlrval.FromTypeErrorBinary("%", input1, input2) } var modulus_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -748,7 +749,7 @@ func imodop(input1, input2, input3 *mlrval.Mlrval, iop i_iii_func, funcname stri return input3 } if !input1.IsInt() || !input2.IsInt() || !input3.IsInt() { - return type_error_ternary(funcname, input1, input2, input3) + return mlrval.FromTypeErrorTernary(funcname, input1, input2, input3) } return mlrval.FromInt( @@ -774,8 +775,13 @@ func BIF_mod_mul(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_mod_exp(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { // Pre-check for negative exponent - if input2.IsInt() && input2.AcquireIntValue() < 0 { - return mlrval.ERROR + i2, ok := input2.GetIntValue() + if ok && i2 < 0 { + return mlrval.FromError( + fmt.Errorf( + "mexp: negative exponent disallowed; got %d", i2, + ), + ) } return imodop(input1, input2, input3, imodexp, "mexp") } @@ -846,7 +852,7 @@ func min_s_ss(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func min_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("min", input1, input2) + return mlrval.FromTypeErrorBinary("min", input1, input2) } var min_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -910,7 +916,7 @@ func bif_min_unary_map(input1 *mlrval.Mlrval) *mlrval.Mlrval { var min_unary_dispositions = [mlrval.MT_DIM]UnaryFunc{} func min_unary_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_unary("min", input1) + return mlrval.FromTypeErrorUnary("min", input1) } func init() { @@ -1016,7 +1022,7 @@ func max_s_ss(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func max_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("max", input1, input2) + return mlrval.FromTypeErrorBinary("max", input1, input2) } var max_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -1080,7 +1086,7 @@ func bif_max_unary_map(input1 *mlrval.Mlrval) *mlrval.Mlrval { var max_unary_dispositions = [mlrval.MT_DIM]UnaryFunc{} func max_unary_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_unary("max", input1) + return mlrval.FromTypeErrorUnary("max", input1) } func init() { diff --git a/internal/pkg/bifs/base.go b/internal/pkg/bifs/base.go index dba349c783..c0bf0e8109 100644 --- a/internal/pkg/bifs/base.go +++ b/internal/pkg/bifs/base.go @@ -92,19 +92,6 @@ type ComparatorFunc func(*mlrval.Mlrval, *mlrval.Mlrval) int // and all the same length, so that the disposition matrices will look // reasonable rectangular even after gofmt has been run. -// ---------------------------------------------------------------- -// Type error for unary functions -func type_error_unary(funcname string, input1 *mlrval.Mlrval) *mlrval.Mlrval { - return mlrval.FromError( - fmt.Errorf( - "%s: unacceptable type %s with value %s", - funcname, - input1.GetTypeName(), - input1.StringMaybeQuoted(), - ), - ) -} - // ---------------------------------------------------------------- // Return absent (unary) func _absn1(input1 *mlrval.Mlrval) *mlrval.Mlrval { @@ -136,21 +123,6 @@ func _1u___(input1 *mlrval.Mlrval) *mlrval.Mlrval { return input1 } -// ---------------------------------------------------------------- -// Type error for binary functions -func type_error_binary(funcname string, input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return mlrval.FromError( - fmt.Errorf( - "%s: unacceptable types %s, %s with values %s, %s", - funcname, - input1.GetTypeName(), - input2.GetTypeName(), - input1.StringMaybeQuoted(), - input2.StringMaybeQuoted(), - ), - ) -} - // Return absent (binary) func _absn(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.ABSENT @@ -291,20 +263,3 @@ func type_error_named_argument( ), ) } - -// ---------------------------------------------------------------- -// Type error for ternary functions -func type_error_ternary(funcname string, input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { - return mlrval.FromError( - fmt.Errorf( - "%s: unacceptable types %s, %s, %s with values %s, %s, %s", - funcname, - input1.GetTypeName(), - input2.GetTypeName(), - input3.GetTypeName(), - input1.StringMaybeQuoted(), - input2.StringMaybeQuoted(), - input3.StringMaybeQuoted(), - ), - ) -} diff --git a/internal/pkg/bifs/bits.go b/internal/pkg/bifs/bits.go index 93e0eea15b..7fb786307b 100644 --- a/internal/pkg/bifs/bits.go +++ b/internal/pkg/bifs/bits.go @@ -12,7 +12,7 @@ func bitwise_not_i_i(input1 *mlrval.Mlrval) *mlrval.Mlrval { } func bitwise_not_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_unary("~", input1) + return mlrval.FromTypeErrorUnary("~", input1) } var bitwise_not_dispositions = [mlrval.MT_DIM]UnaryFunc{ @@ -56,7 +56,7 @@ func bitcount_i_i(input1 *mlrval.Mlrval) *mlrval.Mlrval { } func bitcount_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_unary("bitcount", input1) + return mlrval.FromTypeErrorUnary("bitcount", input1) } var bitcount_dispositions = [mlrval.MT_DIM]UnaryFunc{ @@ -85,7 +85,7 @@ func bitwise_and_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func bwandte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("&", input1, input2) + return mlrval.FromTypeErrorBinary("&", input1, input2) } var bitwise_and_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -115,7 +115,7 @@ func bitwise_or_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func bworte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("|", input1, input2) + return mlrval.FromTypeErrorBinary("|", input1, input2) } var bitwise_or_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -145,7 +145,7 @@ func bitwise_xor_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func bwxorte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("^", input1, input2) + return mlrval.FromTypeErrorBinary("^", input1, input2) } var bitwise_xor_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -175,7 +175,7 @@ func lsh_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func lshfte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("<<", input1, input2) + return mlrval.FromTypeErrorBinary("<<", input1, input2) } var left_shift_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -205,7 +205,7 @@ func srsh_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func srste(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary(">>>", input1, input2) + return mlrval.FromTypeErrorBinary(">>>", input1, input2) } var signed_right_shift_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -238,7 +238,7 @@ func ursh_i_ii(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func rste(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary(">>", input1, input2) + return mlrval.FromTypeErrorBinary(">>", input1, input2) } var unsigned_right_shift_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ diff --git a/internal/pkg/bifs/booleans.go b/internal/pkg/bifs/booleans.go index 0364e7a360..da77c61993 100644 --- a/internal/pkg/bifs/booleans.go +++ b/internal/pkg/bifs/booleans.go @@ -12,7 +12,7 @@ func BIF_logical_NOT(input1 *mlrval.Mlrval) *mlrval.Mlrval { if input1.IsBool() { return mlrval.FromBool(!input1.AcquireBoolValue()) } else { - return type_error_unary("!", input1) + return mlrval.FromTypeErrorUnary("!", input1) } } @@ -20,7 +20,7 @@ func BIF_logical_AND(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if input1.IsBool() && input2.IsBool() { return mlrval.FromBool(input1.AcquireBoolValue() && input2.AcquireBoolValue()) } else { - return type_error_unary("&&", input1) + return mlrval.FromTypeErrorUnary("&&", input1) } } @@ -28,7 +28,7 @@ func BIF_logical_OR(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if input1.IsBool() && input2.IsBool() { return mlrval.FromBool(input1.AcquireBoolValue() || input2.AcquireBoolValue()) } else { - return type_error_unary("||", input1) + return mlrval.FromTypeErrorUnary("||", input1) } } @@ -36,6 +36,6 @@ func BIF_logical_XOR(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if input1.IsBool() && input2.IsBool() { return mlrval.FromBool(input1.AcquireBoolValue() != input2.AcquireBoolValue()) } else { - return type_error_unary("^^", input1) + return mlrval.FromTypeErrorUnary("^^", input1) } } diff --git a/internal/pkg/bifs/cmp.go b/internal/pkg/bifs/cmp.go index 670a3e7ba1..7d31cb7eea 100644 --- a/internal/pkg/bifs/cmp.go +++ b/internal/pkg/bifs/cmp.go @@ -271,7 +271,7 @@ func ne_b_mm(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { var eq_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{} func eqte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("==", input1, input2) + return mlrval.FromTypeErrorBinary("==", input1, input2) } func init() { @@ -292,7 +292,7 @@ func init() { } func nete(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("!=", input1, input2) + return mlrval.FromTypeErrorBinary("!=", input1, input2) } var ne_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -311,7 +311,7 @@ var ne_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ } func gtte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary(">", input1, input2) + return mlrval.FromTypeErrorBinary(">", input1, input2) } var gt_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -330,7 +330,7 @@ var gt_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ } func gete(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary(">=", input1, input2) + return mlrval.FromTypeErrorBinary(">=", input1, input2) } var ge_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -349,7 +349,7 @@ var ge_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ } func ltte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("<", input1, input2) + return mlrval.FromTypeErrorBinary("<", input1, input2) } var lt_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -368,7 +368,7 @@ var lt_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ } func lete(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("<=", input1, input2) + return mlrval.FromTypeErrorBinary("<=", input1, input2) } var le_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -387,7 +387,7 @@ var le_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ } func cmpte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("<=>", input1, input2) + return mlrval.FromTypeErrorBinary("<=>", input1, input2) } var cmp_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ diff --git a/internal/pkg/bifs/collections.go b/internal/pkg/bifs/collections.go index 34e0da1bb2..946a43b8ec 100644 --- a/internal/pkg/bifs/collections.go +++ b/internal/pkg/bifs/collections.go @@ -66,7 +66,7 @@ func depth_from_scalar(input1 *mlrval.Mlrval) *mlrval.Mlrval { var depth_dispositions = [mlrval.MT_DIM]UnaryFunc{} func depth_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_unary("depth", input1) + return mlrval.FromTypeErrorUnary("depth", input1) } func init() { @@ -139,7 +139,7 @@ func leafcount_from_scalar(input1 *mlrval.Mlrval) *mlrval.Mlrval { } func leafcount_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_unary("leafcount", input1) + return mlrval.FromTypeErrorUnary("leafcount", input1) } var leafcount_dispositions = [mlrval.MT_DIM]UnaryFunc{ diff --git a/internal/pkg/bifs/mathlib.go b/internal/pkg/bifs/mathlib.go index 79ea45e552..b18e0d4ed1 100644 --- a/internal/pkg/bifs/mathlib.go +++ b/internal/pkg/bifs/mathlib.go @@ -14,7 +14,7 @@ import ( // ---------------------------------------------------------------- // Return error (unary math-library func) func _math_unary_erro1(input1 *mlrval.Mlrval, f mathLibUnaryFunc, fname string) *mlrval.Mlrval { - return type_error_unary(fname, input1) + return mlrval.FromTypeErrorUnary(fname, input1) } // Return absent (unary math-library func) @@ -185,7 +185,7 @@ func pow_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func powte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("**", input1, input2) + return mlrval.FromTypeErrorBinary("**", input1, input2) } var pow_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -222,7 +222,7 @@ func atan2_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func atan2te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("atan2", input1, input2) + return mlrval.FromTypeErrorBinary("atan2", input1, input2) } var atan2_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -263,7 +263,7 @@ func roundm_f_ff(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func rdmte(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("roundm", input1, input2) + return mlrval.FromTypeErrorBinary("roundm", input1, input2) } var roundm_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -287,7 +287,7 @@ func BIF_roundm(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { // ================================================================ func logifit_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("logifit", input1, input2) + return mlrval.FromTypeErrorBinary("logifit", input1, input2) } func BIF_logifit(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { diff --git a/internal/pkg/bifs/stats.go b/internal/pkg/bifs/stats.go index 6799b8fa53..2aba104ce4 100644 --- a/internal/pkg/bifs/stats.go +++ b/internal/pkg/bifs/stats.go @@ -168,7 +168,7 @@ func check_collection(c *mlrval.Mlrval, funcname string) (bool, *mlrval.Mlrval) case mlrval.MT_ERROR: return false, c default: - return false, type_error_unary(funcname, c) + return false, mlrval.FromTypeErrorUnary(funcname, c) } } diff --git a/internal/pkg/bifs/stats_test.go b/internal/pkg/bifs/stats_test.go index 0d1276ba18..3fc21c84aa 100644 --- a/internal/pkg/bifs/stats_test.go +++ b/internal/pkg/bifs/stats_test.go @@ -72,7 +72,7 @@ func TestBIF_null_count(t *testing.T) { mlrval.FromInt(1), mlrval.FromString("two"), mlrval.FromString(""), // this counts - mlrval.ERROR, + mlrval.FromAnonymousError(), mlrval.ABSENT, mlrval.NULL, // this counts }) diff --git a/internal/pkg/bifs/strings.go b/internal/pkg/bifs/strings.go index d7d885281e..8a99277c32 100644 --- a/internal/pkg/bifs/strings.go +++ b/internal/pkg/bifs/strings.go @@ -13,7 +13,7 @@ import ( // ================================================================ func BIF_strlen(input1 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsStringOrVoid() { - return type_error_unary("strlen", input1) + return mlrval.FromTypeErrorUnary("strlen", input1) } else { return mlrval.FromInt(lib.UTF8Strlen(input1.AcquireStringValue())) } @@ -43,7 +43,7 @@ func dot_s_xx(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func dot_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary(".", input1, input2) + return mlrval.FromTypeErrorBinary(".", input1, input2) } var dot_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ @@ -74,7 +74,7 @@ func BIF_substr_1_up(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.ABSENT } if input1.IsError() { - return type_error_unary("substr1", input1) + return mlrval.FromTypeErrorUnary("substr1", input1) } sinput := input1.String() @@ -106,7 +106,7 @@ func BIF_substr_0_up(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.ABSENT } if input1.IsError() { - return type_error_unary("substr0", input1) + return mlrval.FromTypeErrorUnary("substr0", input1) } sinput := input1.String() @@ -138,7 +138,7 @@ func BIF_index(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.ABSENT } if input1.IsError() { - return type_error_unary("index", input1) + return mlrval.FromTypeErrorUnary("index", input1) } sinput1 := input1.String() sinput2 := input2.String() @@ -176,13 +176,13 @@ func BIF_truncate(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return input2 } if !input1.IsStringOrVoid() { - return type_error_unary("truncate", input1) + return mlrval.FromTypeErrorUnary("truncate", input1) } if !input2.IsInt() { - return type_error_unary("truncate", input2) + return mlrval.FromTypeErrorUnary("truncate", input2) } if input2.AcquireIntValue() < 0 { - return type_error_unary("truncate", input2) + return mlrval.FromTypeErrorUnary("truncate", input2) } // Handle UTF-8 correctly: len(input1.AcquireStringValue()) will count bytes, not runes. @@ -209,7 +209,7 @@ func BIF_leftpad(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { } if !input2.IsInt() { - return type_error_unary("leftpad", input2) + return mlrval.FromTypeErrorUnary("leftpad", input2) } inputString := input1.String() @@ -242,7 +242,7 @@ func BIF_rightpad(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { } if !input2.IsInt() { - return type_error_unary("rightpad", input2) + return mlrval.FromTypeErrorUnary("rightpad", input2) } inputString := input1.String() @@ -357,7 +357,7 @@ func BIF_format(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval { } formatString, ok := mlrvals[0].GetStringValue() if !ok { // not a string - return type_error_unary("format", mlrvals[0]) + return mlrval.FromTypeErrorUnary("format", mlrvals[0]) } pieces := lib.SplitString(formatString, "{}") @@ -409,11 +409,11 @@ func BIF_unformatx(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { func bif_unformat_aux(input1, input2 *mlrval.Mlrval, inferTypes bool) *mlrval.Mlrval { template, ok1 := input1.GetStringValue() if !ok1 { - return type_error_unary("unformat", input1) + return mlrval.FromTypeErrorUnary("unformat", input1) } input, ok2 := input2.GetStringValue() if !ok2 { - return type_error_unary("unformat", input2) + return mlrval.FromTypeErrorUnary("unformat", input2) } templatePieces := strings.Split(template, "{}") @@ -470,7 +470,7 @@ func BIF_hexfmt(input1 *mlrval.Mlrval) *mlrval.Mlrval { // ---------------------------------------------------------------- func fmtnum_is(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsString() { - return type_error_unary("fmtnum", input2) + return mlrval.FromTypeErrorUnary("fmtnum", input2) } formatString := input2.AcquireStringValue() formatter, err := mlrval.GetFormatter(formatString) @@ -483,7 +483,7 @@ func fmtnum_is(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { func fmtnum_fs(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsString() { - return type_error_unary("fmtnum", input2) + return mlrval.FromTypeErrorUnary("fmtnum", input2) } formatString := input2.AcquireStringValue() formatter, err := mlrval.GetFormatter(formatString) @@ -496,7 +496,7 @@ func fmtnum_fs(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { func fmtnum_bs(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsString() { - return type_error_unary("fmtnum", input2) + return mlrval.FromTypeErrorUnary("fmtnum", input2) } formatString := input2.AcquireStringValue() formatter, err := mlrval.GetFormatter(formatString) @@ -510,7 +510,7 @@ func fmtnum_bs(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func fmtnum_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("fmtnum", input1, input2) + return mlrval.FromTypeErrorBinary("fmtnum", input1, input2) } var fmtnum_dispositions = [mlrval.MT_DIM][mlrval.MT_DIM]BinaryFunc{ diff --git a/internal/pkg/bifs/types.go b/internal/pkg/bifs/types.go index c1c63819c8..b57e0dc849 100644 --- a/internal/pkg/bifs/types.go +++ b/internal/pkg/bifs/types.go @@ -21,7 +21,14 @@ func string_to_int(input1 *mlrval.Mlrval) *mlrval.Mlrval { if ok { return mlrval.FromInt(i) } else { - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf( + "%s: unacceptable value %s with type %s", + "int", + input1.StringMaybeQuoted(), + input1.GetTypeName(), + ), + ) } } @@ -38,7 +45,7 @@ func bool_to_int(input1 *mlrval.Mlrval) *mlrval.Mlrval { } func to_int_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_unary("int", input1) + return mlrval.FromTypeErrorUnary("int", input1) } var to_int_dispositions = [mlrval.MT_DIM]UnaryFunc{ @@ -65,7 +72,14 @@ func string_to_int_with_base(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if ok { return mlrval.FromInt(i) } else { - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf( + "%s: unacceptable value %s with type %s", + "int", + input1.StringMaybeQuoted(), + input1.GetTypeName(), + ), + ) } } @@ -86,7 +100,7 @@ func bool_to_int_with_base(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } func to_int_with_base_te(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_binary("int", input1, input2) + return mlrval.FromTypeErrorBinary("int", input1, input2) } var to_int_with_base_dispositions = [mlrval.MT_DIM]BinaryFunc{ @@ -105,7 +119,7 @@ var to_int_with_base_dispositions = [mlrval.MT_DIM]BinaryFunc{ func BIF_int_with_base(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsInt() { - return type_error_binary("int", input1, input2) + return mlrval.FromTypeErrorBinary("int", input1, input2) } return to_int_with_base_dispositions[input1.Type()](input1, input2) } @@ -116,7 +130,14 @@ func string_to_float(input1 *mlrval.Mlrval) *mlrval.Mlrval { if ok { return mlrval.FromFloat(f) } else { - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf( + "%s: unacceptable value %s with type %s", + "float", + input1.StringMaybeQuoted(), + input1.GetTypeName(), + ), + ) } } @@ -133,7 +154,7 @@ func bool_to_float(input1 *mlrval.Mlrval) *mlrval.Mlrval { } func to_float_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_unary("float", input1) + return mlrval.FromTypeErrorUnary("float", input1) } var to_float_dispositions = [mlrval.MT_DIM]UnaryFunc{ @@ -160,7 +181,14 @@ func string_to_boolean(input1 *mlrval.Mlrval) *mlrval.Mlrval { if ok { return mlrval.FromBool(b) } else { - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf( + "%s: unacceptable value %s with type %s", + "boolean", + input1.StringMaybeQuoted(), + input1.GetTypeName(), + ), + ) } } @@ -173,7 +201,7 @@ func float_to_bool(input1 *mlrval.Mlrval) *mlrval.Mlrval { } func to_boolean_te(input1 *mlrval.Mlrval) *mlrval.Mlrval { - return type_error_unary("boolean", input1) + return mlrval.FromTypeErrorUnary("boolean", input1) } var to_boolean_dispositions = [mlrval.MT_DIM]UnaryFunc{ diff --git a/internal/pkg/dsl/cst/env.go b/internal/pkg/dsl/cst/env.go index 24e2647bb7..73e37c3437 100644 --- a/internal/pkg/dsl/cst/env.go +++ b/internal/pkg/dsl/cst/env.go @@ -41,7 +41,7 @@ func (node *EnvironmentVariableNode) Evaluate( return mlrval.ABSENT.StrictModeCheck(state.StrictMode, "ENV[(absent)]") } if !name.IsString() { - return mlrval.ERROR + return mlrval.FromTypeErrorUnary("ENV[]", name) } return mlrval.FromString(os.Getenv(name.String())) diff --git a/internal/pkg/mlrval/mlrval_new.go b/internal/pkg/mlrval/mlrval_new.go index c92152ec4d..956541ced7 100644 --- a/internal/pkg/mlrval/mlrval_new.go +++ b/internal/pkg/mlrval/mlrval_new.go @@ -5,6 +5,9 @@ package mlrval import ( + "errors" + "fmt" + "github.com/johnkerl/miller/internal/pkg/lib" ) @@ -38,6 +41,62 @@ func FromError(err error) *Mlrval { } } +func FromErrorString(err string) *Mlrval { + return &Mlrval{ + mvtype: MT_ERROR, + err: errors.New(err), + printrep: ERROR_PRINTREP, + printrepValid: true, + } +} + +func FromAnonymousError() *Mlrval { + return &Mlrval{ + mvtype: MT_ERROR, + printrep: ERROR_PRINTREP, + printrepValid: true, + } +} + +func FromTypeErrorUnary(funcname string, input1 *Mlrval) *Mlrval { + return FromError( + fmt.Errorf( + "%s: unacceptable type %s with value %s", + funcname, + input1.GetTypeName(), + input1.StringMaybeQuoted(), + ), + ) +} + +func FromTypeErrorBinary(funcname string, input1, input2 *Mlrval) *Mlrval { + return FromError( + fmt.Errorf( + "%s: unacceptable types %s, %s with values %s, %s", + funcname, + input1.GetTypeName(), + input2.GetTypeName(), + input1.StringMaybeQuoted(), + input2.StringMaybeQuoted(), + ), + ) +} + +func FromTypeErrorTernary(funcname string, input1, input2, input3 *Mlrval) *Mlrval { + return FromError( + fmt.Errorf( + "%s: unacceptable types %s, %s, %s with values %s, %s, %s", + funcname, + input1.GetTypeName(), + input2.GetTypeName(), + input3.GetTypeName(), + input1.StringMaybeQuoted(), + input2.StringMaybeQuoted(), + input3.StringMaybeQuoted(), + ), + ) +} + // TODO: comment non-JIT context like mlr put -s. // TODO: comment re inferBool. func FromInferredType(input string) *Mlrval { diff --git a/internal/pkg/terminals/help/entry.go b/internal/pkg/terminals/help/entry.go index 17130fe26d..6598c48b31 100644 --- a/internal/pkg/terminals/help/entry.go +++ b/internal/pkg/terminals/help/entry.go @@ -488,7 +488,7 @@ func helpTypeArithmeticInfo() { mlrval.FromFloat(2.5), mlrval.VOID, mlrval.ABSENT, - mlrval.ERROR, + mlrval.FromAnonymousError(), } n := len(mlrvals) diff --git a/internal/pkg/transformers/fraction.go b/internal/pkg/transformers/fraction.go index 2754504497..9327ce2088 100644 --- a/internal/pkg/transformers/fraction.go +++ b/internal/pkg/transformers/fraction.go @@ -2,6 +2,7 @@ package transformers import ( "container/list" + "errors" "fmt" "os" "strings" @@ -269,7 +270,11 @@ func (tr *TransformerFraction) Transform( outputValue = bifs.BIF_divide(numerator, denominator) outputValue = bifs.BIF_times(outputValue, tr.multiplier) } else { - outputValue = mlrval.ERROR + outputValue = mlrval.FromError( + errors.New( + "mlr fraction: division by zero", + ), + ) } outrec.PutCopy( diff --git a/internal/pkg/transformers/utils/percentile_keeper.go b/internal/pkg/transformers/utils/percentile_keeper.go index c9f2453bd3..3b901ce133 100644 --- a/internal/pkg/transformers/utils/percentile_keeper.go +++ b/internal/pkg/transformers/utils/percentile_keeper.go @@ -149,7 +149,9 @@ func (keeper *PercentileKeeper) EmitNamed(name string) *mlrval.Mlrval { } } else { - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf(`stats1: unrecognized percentilename "%s"`, name), + ) } } diff --git a/test/cases/io-spec-tsv/0004/expout b/test/cases/io-spec-tsv/0004/expout index e69de29bb2..f741e40d49 100644 --- a/test/cases/io-spec-tsv/0004/expout +++ b/test/cases/io-spec-tsv/0004/expout @@ -0,0 +1,8 @@ +[ +{ + "a": 1 +}, +{ + "a": 2 +} +] diff --git a/xtodo.txt b/xtodo.txt index 1bf03a171f..fb8174bd89 100644 --- a/xtodo.txt +++ b/xtodo.txt @@ -1,3 +1,4 @@ +---------------------------------------------------------------- * _erro and _erro1 rid entirely of * other modules obv ... long and winding road ... * optional env var: MLR_DATA_ERROR_FAIL_FAST or somesuch @@ -5,3 +6,73 @@ * look at: mr -vvv test/cases/io-spec-tsv/0004/cmd grep -c mlrval.ERROR $(rg -wl mlrval.ERROR|sort) + +mlr -x --from x --csv fraction -f c + +---------------------------------------------------------------- + +func (keeper *PercentileKeeper) EmitNamed(name string) *mlrval.Mlrval { + if name == "min" { + return keeper.EmitNonInterpolated(0.0) + } else if name == "p25" { + return keeper.EmitNonInterpolated(25.0) + } else if name == "median" { + return keeper.EmitNonInterpolated(50.0) + } else if name == "p75" { + return keeper.EmitNonInterpolated(75.0) + } else if name == "max" { + return keeper.EmitNonInterpolated(100.0) + + } else if name == "iqr" { + p25 := keeper.EmitNonInterpolated(25.0) + p75 := keeper.EmitNonInterpolated(75.0) + if p25.IsNumeric() && p75.IsNumeric() { + return bifs.BIF_minus_binary(p75, p25) + } else { + return mlrval.VOID + } + + } else if name == "lof" { + p25 := keeper.EmitNonInterpolated(25.0) + iqr := keeper.EmitNamed("iqr") + if p25.IsNumeric() && iqr.IsNumeric() { + return bifs.BIF_minus_binary(p25, bifs.BIF_times(fenceOuterK, iqr)) + } else { + return mlrval.VOID + } + + } else if name == "lif" { + p25 := keeper.EmitNonInterpolated(25.0) + iqr := keeper.EmitNamed("iqr") + if p25.IsNumeric() && iqr.IsNumeric() { + return bifs.BIF_minus_binary(p25, bifs.BIF_times(fenceInnerK, iqr)) + } else { + return mlrval.VOID + } + + } else if name == "uif" { + p75 := keeper.EmitNonInterpolated(25.0) + iqr := keeper.EmitNamed("iqr") + if p75.IsNumeric() && iqr.IsNumeric() { + return bifs.BIF_plus_binary(p75, bifs.BIF_times(fenceInnerK, iqr)) + } else { + return mlrval.VOID + } + + } else if name == "uof" { + p75 := keeper.EmitNonInterpolated(25.0) + iqr := keeper.EmitNamed("iqr") + if p75.IsNumeric() && iqr.IsNumeric() { + return bifs.BIF_plus_binary(p75, bifs.BIF_times(fenceOuterK, iqr)) + } else { + return mlrval.VOID + } + + } else { + return mlrval.FromError( + errors.New( + "stats1: unrecognized + ), + ) + } +} From 6cfe2b90d948f7a04666e3abbb300522213475ec Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 29 Aug 2023 09:44:19 -0400 Subject: [PATCH 13/22] more --- internal/pkg/bifs/hashing.go | 8 +-- internal/pkg/bifs/random.go | 8 +-- internal/pkg/bifs/stats.go | 6 +- internal/pkg/bifs/system.go | 10 +-- internal/pkg/dsl/cst/hofs.go | 108 +++++++++++++++--------------- internal/pkg/mlrval/mlrval_get.go | 16 +++++ internal/pkg/mlrval/mlrval_new.go | 58 +++++++++++++--- 7 files changed, 134 insertions(+), 80 deletions(-) diff --git a/internal/pkg/bifs/hashing.go b/internal/pkg/bifs/hashing.go index 6c6c0ce399..09552ab0f3 100644 --- a/internal/pkg/bifs/hashing.go +++ b/internal/pkg/bifs/hashing.go @@ -12,7 +12,7 @@ import ( func BIF_md5(input1 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("md5", input1) } else { return mlrval.FromString( fmt.Sprintf( @@ -25,7 +25,7 @@ func BIF_md5(input1 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_sha1(input1 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("sha1", input1) } else { return mlrval.FromString( fmt.Sprintf( @@ -38,7 +38,7 @@ func BIF_sha1(input1 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_sha256(input1 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("sha256", input1) } else { return mlrval.FromString( fmt.Sprintf( @@ -51,7 +51,7 @@ func BIF_sha256(input1 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_sha512(input1 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("sha512", input1) } else { return mlrval.FromString( fmt.Sprintf( diff --git a/internal/pkg/bifs/random.go b/internal/pkg/bifs/random.go index 3662b00b45..2e9cd105ff 100644 --- a/internal/pkg/bifs/random.go +++ b/internal/pkg/bifs/random.go @@ -30,10 +30,10 @@ func BIF_urandint(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return input2 } if !input1.IsInt() { - return mlrval.ERROR + return mlrval.FromNotIntError("urandint", input1) } if !input2.IsInt() { - return mlrval.ERROR + return mlrval.FromNotIntError("urandint", input2) } a := input1.AcquireIntValue() @@ -62,10 +62,10 @@ func BIF_urandrange(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { a, aok := input1.GetNumericToFloatValue() b, bok := input2.GetNumericToFloatValue() if !aok { - return mlrval.ERROR + return mlrval.FromNotIntOrFloatError("urandrange", input1) } if !bok { - return mlrval.ERROR + return mlrval.FromNotIntOrFloatError("urandrange", input2) } return mlrval.FromFloat( a + (b-a)*lib.RandFloat64(), diff --git a/internal/pkg/bifs/stats.go b/internal/pkg/bifs/stats.go index 2aba104ce4..c809f71671 100644 --- a/internal/pkg/bifs/stats.go +++ b/internal/pkg/bifs/stats.go @@ -168,7 +168,7 @@ func check_collection(c *mlrval.Mlrval, funcname string) (bool, *mlrval.Mlrval) case mlrval.MT_ERROR: return false, c default: - return false, mlrval.FromTypeErrorUnary(funcname, c) + return false, mlrval.FromNotCollectionError(funcname, c) } } @@ -605,7 +605,7 @@ func bif_percentiles_with_options_aux( var sorted_array *mlrval.Mlrval if array_is_sorted { if !collection.IsArray() { - return type_error_named_argument(funcname, "array", "collection", collection) + return mlrval.FromNotArrayError(funcname+" collection", collection) } sorted_array = collection } else { @@ -631,7 +631,7 @@ func bif_percentiles_impl( ps := percentiles.GetArray() if ps == nil { // not an array - return type_error_named_argument(funcname, "array", "percentiles", percentiles) + return mlrval.FromNotArrayError(funcname+" percentiles", percentiles) } outputs := make([]*mlrval.Mlrval, len(ps)) diff --git a/internal/pkg/bifs/system.go b/internal/pkg/bifs/system.go index 90dedb56fa..a3ac73ad41 100644 --- a/internal/pkg/bifs/system.go +++ b/internal/pkg/bifs/system.go @@ -22,7 +22,7 @@ func BIF_os() *mlrval.Mlrval { func BIF_hostname() *mlrval.Mlrval { hostname, err := os.Hostname() if err != nil { - return mlrval.ERROR + return mlrval.FromErrorString("could not retrieve system hostname") } else { return mlrval.FromString(hostname) } @@ -30,7 +30,7 @@ func BIF_hostname() *mlrval.Mlrval { func BIF_system(input1 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("system", input1) } commandString := input1.AcquireStringValue() @@ -38,7 +38,7 @@ func BIF_system(input1 *mlrval.Mlrval) *mlrval.Mlrval { outputBytes, err := exec.Command(shellRunArray[0], shellRunArray[1:]...).Output() if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } outputString := strings.TrimRight(string(outputBytes), "\n") @@ -48,7 +48,7 @@ func BIF_system(input1 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_exec(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval { if len(mlrvals) == 0 { - return mlrval.ERROR + return mlrval.FromErrorString("exec: zero-length input given") } cmd := exec.Command(mlrvals[0].String()) @@ -96,7 +96,7 @@ func BIF_exec(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval { } if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } outputString := strings.TrimRight(string(outputBytes), "\n") diff --git a/internal/pkg/dsl/cst/hofs.go b/internal/pkg/dsl/cst/hofs.go index e47f32ce10..b6d710b6cb 100644 --- a/internal/pkg/dsl/cst/hofs.go +++ b/internal/pkg/dsl/cst/hofs.go @@ -207,7 +207,7 @@ func SelectHOF( } else if input1.IsMap() { return selectMap(input1, input2, state) } else { - return mlrval.ERROR + return mlrval.FromNotCollectionError("select", input1) } } @@ -216,9 +216,9 @@ func selectArray( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputArray := input1.GetArray() + inputArray, errVal := input1.GetArrayOrError("select") if inputArray == nil { // not an array - return mlrval.ERROR + return errVal } isFunctionOrDie(input2, "select") @@ -252,9 +252,9 @@ func selectMap( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputMap := input1.GetMap() + inputMap, errVal := input1.GetMapOrError("select") if inputMap == nil { // not a map - return mlrval.ERROR + return errVal } isFunctionOrDie(input2, "select") @@ -298,7 +298,7 @@ func ApplyHOF( } else if input1.IsMap() { return applyMap(input1, input2, state) } else { - return mlrval.ERROR + return mlrval.FromNotCollectionError("apply", input1) } } @@ -307,9 +307,9 @@ func applyArray( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputArray := input1.GetArray() - if inputArray == nil { // not an array - return mlrval.ERROR + inputArray, errVal := input1.GetArrayOrError("apply") + if inputArray == nil { + return errVal } isFunctionOrDie(input2, "apply") @@ -334,9 +334,9 @@ func applyMap( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputMap := input1.GetMap() + inputMap, errVal := input1.GetMapOrError("apply") if inputMap == nil { // not a map - return mlrval.ERROR + return errVal } isFunctionOrDie(input2, "apply") @@ -369,7 +369,7 @@ func ReduceHOF( } else if input1.IsMap() { return reduceMap(input1, input2, state) } else { - return mlrval.ERROR + return mlrval.FromNotCollectionError("reduce", input1) } } @@ -378,9 +378,9 @@ func reduceArray( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputArray := input1.GetArray() - if inputArray == nil { // not an array - return mlrval.ERROR + inputArray, errVal := input1.GetArrayOrError("reduce") + if inputArray == nil { + return errVal } isFunctionOrDie(input2, "reduce") @@ -408,9 +408,9 @@ func reduceMap( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputMap := input1.GetMap() + inputMap, errVal := input1.GetMapOrError("reduce") if inputMap == nil { // not a map - return mlrval.ERROR + return errVal } isFunctionOrDie(input2, "reduce") @@ -449,7 +449,7 @@ func FoldHOF( } else if input1.IsMap() { return foldMap(input1, input2, input3, state) } else { - return mlrval.ERROR + return mlrval.FromNotCollectionError("fold", input1) } } @@ -459,9 +459,9 @@ func foldArray( input3 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputArray := input1.GetArray() - if inputArray == nil { // not an array - return mlrval.ERROR + inputArray, errVal := input1.GetArrayOrError("fold") + if inputArray == nil { + return errVal } isFunctionOrDie(input2, "fold") @@ -486,9 +486,9 @@ func foldMap( input3 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputMap := input1.GetMap() + inputMap, errVal := input1.GetMapOrError("fold") if inputMap == nil { // not a map - return mlrval.ERROR + return errVal } isFunctionOrDie(input2, "fold") @@ -528,7 +528,7 @@ func SortHOF( } else if inputs[0].IsMap() { return sortM(inputs[0], "") } else { - return mlrval.ERROR + return mlrval.FromNotCollectionError("sort", inputs[0]) } } else if inputs[1].IsStringOrVoid() { @@ -537,7 +537,7 @@ func SortHOF( } else if inputs[0].IsMap() { return sortM(inputs[0], inputs[1].String()) } else { - return mlrval.ERROR + return mlrval.FromNotCollectionError("sort", inputs[0]) } } else if inputs[1].IsFunction() { @@ -546,7 +546,7 @@ func SortHOF( } else if inputs[0].IsMap() { return sortMF(inputs[0], inputs[1], state) } else { - return mlrval.ERROR + return mlrval.FromNotCollectionError("sort", inputs[0]) } } else { @@ -555,7 +555,9 @@ func SortHOF( ) os.Exit(1) } - return mlrval.ERROR + // Not reached + lib.InternalCodingErrorIf(true) + return nil } // ---------------------------------------------------------------- @@ -600,10 +602,10 @@ func sortA( input1 *mlrval.Mlrval, flags string, ) *mlrval.Mlrval { - if input1.GetArray() == nil { // not an array - return mlrval.ERROR + temp, errVal := input1.GetArrayOrError("sort") + if temp == nil { // not an array + return errVal } - output := input1.Copy() // byMapValue is ignored for sorting arrays @@ -677,19 +679,19 @@ func sortM( input1 *mlrval.Mlrval, flags string, ) *mlrval.Mlrval { - inmap := input1.GetMap() - if inmap == nil { // not a map - return mlrval.ERROR + inputMap, errVal := input1.GetMapOrError("sort") + if inputMap == nil { // not a map + return errVal } // Get sort-flags, if provided sortType, reverse, byMapValue := decodeSortFlags(flags) // Copy the entries to an array for sorting. - n := inmap.FieldCount + n := inputMap.FieldCount entries := make([]mlrval.MlrmapEntryForArray, n) i := 0 - for pe := inmap.Head; pe != nil; pe = pe.Next { + for pe := inputMap.Head; pe != nil; pe = pe.Next { entries[i].Key = pe.Key entries[i].Value = pe.Value // pointer alias for now until new map at end of this function i++ @@ -838,13 +840,11 @@ func sortAF( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputArray := input1.GetArray() + inputArray, errVal := input1.GetArrayOrError("select") if inputArray == nil { // not an array - return mlrval.ERROR - } - if !input2.IsFunction() { - return mlrval.ERROR + return errVal } + isFunctionOrDie(input2, "sort") hofSpace := getHOFSpace(input2, 2, "sort", "array") udfCallsite := hofSpace.udfCallsite @@ -881,13 +881,11 @@ func sortMF( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputMap := input1.GetMap() + inputMap, errVal := input1.GetMapOrError("sort") if inputMap == nil { // not a map - return mlrval.ERROR - } - if !input2.IsFunction() { - return mlrval.ERROR + return errVal } + isFunctionOrDie(input2, "sort") pairsArray := inputMap.ToPairsArray() @@ -936,7 +934,7 @@ func AnyHOF( } else if input1.IsMap() { return anyMap(input1, input2, state) } else { - return mlrval.ERROR + return mlrval.FromNotCollectionError("any", input1) } } @@ -945,9 +943,9 @@ func anyArray( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputArray := input1.GetArray() + inputArray, errVal := input1.GetArrayOrError("any") if inputArray == nil { // not an array - return mlrval.ERROR + return errVal } isFunctionOrDie(input2, "any") @@ -981,9 +979,9 @@ func anyMap( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputMap := input1.GetMap() + inputMap, errVal := input1.GetMapOrError("any") if inputMap == nil { // not a map - return mlrval.ERROR + return errVal } isFunctionOrDie(input2, "any") @@ -1028,7 +1026,7 @@ func EveryHOF( } else if input1.IsMap() { return everyMap(input1, input2, state) } else { - return mlrval.ERROR + return mlrval.FromNotCollectionError("every", input1) } } @@ -1037,9 +1035,9 @@ func everyArray( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputArray := input1.GetArray() + inputArray, errVal := input1.GetArrayOrError("every") if inputArray == nil { // not an array - return mlrval.ERROR + return errVal } isFunctionOrDie(input2, "every") @@ -1073,9 +1071,9 @@ func everyMap( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputMap := input1.GetMap() + inputMap, errVal := input1.GetMapOrError("every") if inputMap == nil { // not a map - return mlrval.ERROR + return errVal } isFunctionOrDie(input2, "every") diff --git a/internal/pkg/mlrval/mlrval_get.go b/internal/pkg/mlrval/mlrval_get.go index 68d15e8669..68b4b6e5e9 100644 --- a/internal/pkg/mlrval/mlrval_get.go +++ b/internal/pkg/mlrval/mlrval_get.go @@ -71,6 +71,14 @@ func (mv *Mlrval) GetArray() []*Mlrval { } } +func (mv *Mlrval) GetArrayOrError(funcname string) (ok []*Mlrval, err *Mlrval) { + if mv.IsArray() { + return mv.intf.([]*Mlrval), nil + } else { + return nil, FromNotArrayError(funcname, mv) + } +} + func (mv *Mlrval) GetMap() *Mlrmap { if mv.IsMap() { return mv.intf.(*Mlrmap) @@ -79,6 +87,14 @@ func (mv *Mlrval) GetMap() *Mlrmap { } } +func (mv *Mlrval) GetMapOrError(funcname string) (ok *Mlrmap, err *Mlrval) { + if mv.IsMap() { + return mv.intf.(*Mlrmap), nil + } else { + return nil, FromNotMapError(funcname, mv) + } +} + func (mv *Mlrval) GetFunction() interface{} { if mv.Type() == MT_FUNC { return mv.intf diff --git a/internal/pkg/mlrval/mlrval_new.go b/internal/pkg/mlrval/mlrval_new.go index 956541ced7..e3ef59ccb0 100644 --- a/internal/pkg/mlrval/mlrval_new.go +++ b/internal/pkg/mlrval/mlrval_new.go @@ -58,45 +58,85 @@ func FromAnonymousError() *Mlrval { } } -func FromTypeErrorUnary(funcname string, input1 *Mlrval) *Mlrval { +func FromTypeErrorUnary(funcname string, v *Mlrval) *Mlrval { return FromError( fmt.Errorf( "%s: unacceptable type %s with value %s", funcname, - input1.GetTypeName(), - input1.StringMaybeQuoted(), + v.GetTypeName(), + v.StringMaybeQuoted(), ), ) } -func FromTypeErrorBinary(funcname string, input1, input2 *Mlrval) *Mlrval { +func FromTypeErrorBinary(funcname string, v, input2 *Mlrval) *Mlrval { return FromError( fmt.Errorf( "%s: unacceptable types %s, %s with values %s, %s", funcname, - input1.GetTypeName(), + v.GetTypeName(), input2.GetTypeName(), - input1.StringMaybeQuoted(), + v.StringMaybeQuoted(), input2.StringMaybeQuoted(), ), ) } -func FromTypeErrorTernary(funcname string, input1, input2, input3 *Mlrval) *Mlrval { +func FromTypeErrorTernary(funcname string, v, input2, input3 *Mlrval) *Mlrval { return FromError( fmt.Errorf( "%s: unacceptable types %s, %s, %s with values %s, %s, %s", funcname, - input1.GetTypeName(), + v.GetTypeName(), input2.GetTypeName(), input3.GetTypeName(), - input1.StringMaybeQuoted(), + v.StringMaybeQuoted(), input2.StringMaybeQuoted(), input3.StringMaybeQuoted(), ), ) } +func FromNotStringError(funcname string, v *Mlrval) *Mlrval { + return FromNotNamedTypeError(funcname, v, "string") +} + +func FromNotIntError(funcname string, v *Mlrval) *Mlrval { + return FromNotNamedTypeError(funcname, v, "int") +} + +func FromNotIntOrFloatError(funcname string, v *Mlrval) *Mlrval { + return FromNotNamedTypeError(funcname, v, "int or float") +} + +func FromNotArrayError(funcname string, v *Mlrval) *Mlrval { + return FromNotNamedTypeError(funcname, v, "array") +} + +func FromNotMapError(funcname string, v *Mlrval) *Mlrval { + return FromNotNamedTypeError(funcname, v, "map") +} + +func FromNotCollectionError(funcname string, v *Mlrval) *Mlrval { + return FromNotNamedTypeError(funcname, v, "array or map") +} + +func FromNotFunctionError(funcname string, v *Mlrval) *Mlrval { + return FromNotNamedTypeError(funcname, v, "function") +} + +func FromNotNamedTypeError(funcname string, v *Mlrval, expected_type_name string) *Mlrval { + return FromError( + fmt.Errorf( + "%s: unacceptable non-array value %s with type %s; needed type %s", + funcname, + v.StringMaybeQuoted(), + v.GetTypeName(), + expected_type_name, + ), + ) +} + // TODO: comment non-JIT context like mlr put -s. // TODO: comment re inferBool. func FromInferredType(input string) *Mlrval { From a862e2400559780d99fb611f91b47c3c6e412cb9 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 29 Aug 2023 22:49:10 -0400 Subject: [PATCH 14/22] more --- internal/pkg/bifs/collections.go | 94 ++++++++++----------- internal/pkg/bifs/random.go | 4 +- internal/pkg/bifs/regex.go | 34 ++++---- internal/pkg/bifs/relative_time.go | 16 ++-- internal/pkg/dsl/cst/builtin_functions.go | 4 +- internal/pkg/mlrval/mlrval_new.go | 4 + internal/pkg/transformers/latin1_to_utf8.go | 2 +- internal/pkg/transformers/utf8_to_latin1.go | 2 +- 8 files changed, 82 insertions(+), 78 deletions(-) diff --git a/internal/pkg/bifs/collections.go b/internal/pkg/bifs/collections.go index 946a43b8ec..5d45cd1d4b 100644 --- a/internal/pkg/bifs/collections.go +++ b/internal/pkg/bifs/collections.go @@ -166,7 +166,7 @@ func has_key_in_array(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FALSE } if !input2.IsInt() { - return mlrval.ERROR + return mlrval.FromNotIntError("haskey", input2) } arrayval := input1.AcquireArrayValue() _, ok := unaliasArrayIndex(&arrayval, int(input2.AcquireIntValue())) @@ -177,7 +177,7 @@ func has_key_in_map(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if input2.IsString() || input2.IsInt() { return mlrval.FromBool(input1.AcquireMapValue().Has(input2.String())) } else { - return mlrval.ERROR + return mlrval.FromNotNamedTypeError("haskey", input2, "string or int") } } @@ -187,7 +187,7 @@ func BIF_haskey(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { } else if input1.IsMap() { return has_key_in_map(input1, input2) } else { - return mlrval.ERROR + return mlrval.FromNotCollectionError("haskey", input1) } } @@ -212,10 +212,10 @@ func BIF_concat(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval { // ================================================================ func BIF_mapselect(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval { if len(mlrvals) < 1 { - return mlrval.ERROR + return mlrval.FromErrorString("mapselect: received a zero-length array as input") } if !mlrvals[0].IsMap() { - return mlrval.ERROR + return mlrval.FromNotMapError("mapselect", mlrvals[0]) } oldmap := mlrvals[0].AcquireMapValue() newMap := mlrval.NewMlrmap() @@ -231,11 +231,11 @@ func BIF_mapselect(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval { if element.IsString() { newKeys[element.AcquireStringValue()] = true } else { - return mlrval.ERROR + return mlrval.FromNotStringError("mapselect", element) } } } else { - return mlrval.ERROR + return mlrval.FromNotNamedTypeError("mapselect", selectArg, "string, int, or array") } } @@ -253,10 +253,10 @@ func BIF_mapselect(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval { // ---------------------------------------------------------------- func BIF_mapexcept(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval { if len(mlrvals) < 1 { - return mlrval.ERROR + return mlrval.FromErrorString("mapexcept: received a zero-length array as input") } if !mlrvals[0].IsMap() { - return mlrval.ERROR + return mlrval.FromNotMapError("mapexcept", mlrvals[0]) } newMap := mlrvals[0].AcquireMapValue().Copy() @@ -270,11 +270,11 @@ func BIF_mapexcept(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval { if element.IsString() { newMap.Remove(element.AcquireStringValue()) } else { - return mlrval.ERROR + return mlrval.FromNotStringError("mapselect", element) } } } else { - return mlrval.ERROR + return mlrval.FromNotNamedTypeError("mapexcept", exceptArg, "string, int, or array") } } @@ -290,13 +290,13 @@ func BIF_mapsum(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval { return mlrvals[0] } if mlrvals[0].Type() != mlrval.MT_MAP { - return mlrval.ERROR + return mlrval.FromNotMapError("mapsum", mlrvals[0]) } newMap := mlrvals[0].AcquireMapValue().Copy() for _, otherMapArg := range mlrvals[1:] { if otherMapArg.Type() != mlrval.MT_MAP { - return mlrval.ERROR + return mlrval.FromNotMapError("mapsum", otherMapArg) } for pe := otherMapArg.AcquireMapValue().Head; pe != nil; pe = pe.Next { @@ -316,13 +316,13 @@ func BIF_mapdiff(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval { return mlrvals[0] } if !mlrvals[0].IsMap() { - return mlrval.ERROR + return mlrval.FromNotMapError("mapdiff", mlrvals[0]) } newMap := mlrvals[0].AcquireMapValue().Copy() for _, otherMapArg := range mlrvals[1:] { if !otherMapArg.IsMap() { - return mlrval.ERROR + return mlrval.FromNotMapError("mapdiff", otherMapArg) } for pe := otherMapArg.AcquireMapValue().Head; pe != nil; pe = pe.Next { @@ -338,7 +338,7 @@ func BIF_mapdiff(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval { // joink({"a":3,"b":4,"c":5}, ",") -> "a,b,c" func BIF_joink(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("joink", input2) } fieldSeparator := input2.AcquireStringValue() if input1.IsMap() { @@ -365,7 +365,7 @@ func BIF_joink(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromString(buffer.String()) } else { - return mlrval.ERROR + return mlrval.FromNotCollectionError("joink", input1) } } @@ -374,7 +374,7 @@ func BIF_joink(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { // joinv({"a":3,"b":4,"c":5}, ",") -> "3,4,5" func BIF_joinv(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("joinv", input2) } fieldSeparator := input2.AcquireStringValue() @@ -401,7 +401,7 @@ func BIF_joinv(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromString(buffer.String()) } else { - return mlrval.ERROR + return mlrval.FromNotCollectionError("joinv", input1) } } @@ -410,11 +410,11 @@ func BIF_joinv(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { // joinkv({"a":3,"b":4,"c":5}, "=", ",") -> "a=3,b=4,c=5" func BIF_joinkv(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("joinkv", input2) } pairSeparator := input2.AcquireStringValue() if !input3.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("joinkv", input3) } fieldSeparator := input3.AcquireStringValue() @@ -446,7 +446,7 @@ func BIF_joinkv(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromString(buffer.String()) } else { - return mlrval.ERROR + return mlrval.FromNotCollectionError("joinkv", input1) } } @@ -454,14 +454,14 @@ func BIF_joinkv(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { // splitkv("a=3,b=4,c=5", "=", ",") -> {"a":3,"b":4,"c":5} func BIF_splitkv(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("splitkv", input1) } if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("splitkv", input2) } pairSeparator := input2.AcquireStringValue() if !input3.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("splitkv", input3) } fieldSeparator := input3.AcquireStringValue() @@ -489,14 +489,14 @@ func BIF_splitkv(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { // splitkvx("a=3,b=4,c=5", "=", ",") -> {"a":"3","b":"4","c":"5"} func BIF_splitkvx(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("splitkvx", input1) } if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("splitkvx", input2) } pairSeparator := input2.AcquireStringValue() if !input3.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("splitkvx", input3) } fieldSeparator := input3.AcquireStringValue() @@ -525,10 +525,10 @@ func BIF_splitkvx(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { // splitnv("a,b,c", ",") -> {"1":"a","2":"b","3":"c"} func BIF_splitnv(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("splitnv", input1) } if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("splitnv", input2) } output := mlrval.FromMap(mlrval.NewMlrmap()) @@ -547,10 +547,10 @@ func BIF_splitnv(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { // splitnvx("3,4,5", ",") -> {"1":"3","2":"4","3":"5"} func BIF_splitnvx(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("splitnvx", input1) } if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("splitnvx", input2) } output := mlrval.FromMap(mlrval.NewMlrmap()) @@ -569,10 +569,10 @@ func BIF_splitnvx(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { // splita("3,4,5", ",") -> [3,4,5] func BIF_splita(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("splita", input1) } if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("splita", input2) } fieldSeparator := input2.AcquireStringValue() @@ -593,10 +593,10 @@ func BIF_splita(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { // e.g. splitax("3,4,5", ",") -> ["3","4","5"] func BIF_splitax(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("splitax", input1) } if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("splitax", input2) } input := input1.AcquireStringValue() fieldSeparator := input2.AcquireStringValue() @@ -640,7 +640,7 @@ func BIF_get_keys(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromArray(arrayval) } else { - return mlrval.ERROR + return mlrval.FromNotCollectionError("get_keys", input1) } } @@ -665,14 +665,14 @@ func BIF_get_values(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromArray(arrayval) } else { - return mlrval.ERROR + return mlrval.FromNotCollectionError("get_values", input1) } } // ---------------------------------------------------------------- func BIF_append(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsArray() { - return mlrval.ERROR + return mlrval.FromNotArrayError("append", input1) } output := input1.Copy() @@ -689,11 +689,11 @@ func BIF_append(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_flatten(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { if input3.IsMap() || input3.IsArray() { if !input1.IsString() && input1.Type() != mlrval.MT_VOID { - return mlrval.ERROR + return mlrval.FromNotStringError("flatten", input1) } prefix := input1.AcquireStringValue() if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("flatten", input2) } delimiter := input2.AcquireStringValue() @@ -715,7 +715,7 @@ func BIF_flatten_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { // unflatten({"a.b.c", ".") is {"a": { "b": { "c": 4}}}. func BIF_unflatten(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("unflatten", input2) } if input1.Type() != mlrval.MT_MAP { return input1 @@ -778,12 +778,12 @@ func BIF_json_parse(input1 *mlrval.Mlrval) *mlrval.Mlrval { if input1.IsVoid() { return input1 } else if !input1.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("json_parse", input1) } else { output := mlrval.FromPending() err := output.UnmarshalJSON([]byte(input1.AcquireStringValue())) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } return output } @@ -792,7 +792,7 @@ func BIF_json_parse(input1 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_json_stringify_unary(input1 *mlrval.Mlrval) *mlrval.Mlrval { outputBytes, err := input1.MarshalJSON(mlrval.JSON_SINGLE_LINE, false) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } else { return mlrval.FromString(string(outputBytes)) } @@ -802,7 +802,7 @@ func BIF_json_stringify_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { var jsonFormatting mlrval.TJSONFormatting = mlrval.JSON_SINGLE_LINE useMultiline, ok := input2.GetBoolValue() if !ok { - return mlrval.ERROR + return mlrval.FromNotBooleanError("json_stringify", input2) } if useMultiline { jsonFormatting = mlrval.JSON_MULTILINE @@ -810,7 +810,7 @@ func BIF_json_stringify_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { outputBytes, err := input1.MarshalJSON(jsonFormatting, false) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } else { return mlrval.FromString(string(outputBytes)) } diff --git a/internal/pkg/bifs/random.go b/internal/pkg/bifs/random.go index 2e9cd105ff..41db35e124 100644 --- a/internal/pkg/bifs/random.go +++ b/internal/pkg/bifs/random.go @@ -75,10 +75,10 @@ func BIF_urandrange(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_urandelement(input1 *mlrval.Mlrval) *mlrval.Mlrval { arrayval := input1.GetArray() if arrayval == nil { // not an array - return mlrval.ERROR + return mlrval.FromNotArrayError("urandelement", input1) } if len(arrayval) == 0 { - return mlrval.ERROR + return mlrval.FromErrorString("urandelement: received a zero-length array as input") } // lo is inclusive, hi is exclusive diff --git a/internal/pkg/bifs/regex.go b/internal/pkg/bifs/regex.go index 41e816f168..72a6878b43 100644 --- a/internal/pkg/bifs/regex.go +++ b/internal/pkg/bifs/regex.go @@ -10,17 +10,17 @@ import ( // BIF_ssub implements the ssub function -- no-frills string-replace, no // regexes, no escape sequences. func BIF_ssub(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { - return bif_ssub_gssub(input1, input2, input3, false) + return bif_ssub_gssub(input1, input2, input3, false, "ssub") } // BIF_gssub implements the gssub function -- no-frills string-replace, no // regexes, no escape sequences. func BIF_gssub(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { - return bif_ssub_gssub(input1, input2, input3, true) + return bif_ssub_gssub(input1, input2, input3, true, "gssub") } // bif_ssub_gssub is shared code for BIF_ssub and BIF_gssub. -func bif_ssub_gssub(input1, input2, input3 *mlrval.Mlrval, doAll bool) *mlrval.Mlrval { +func bif_ssub_gssub(input1, input2, input3 *mlrval.Mlrval, doAll bool, funcname string) *mlrval.Mlrval { if input1.IsErrorOrAbsent() { return input1 } @@ -31,13 +31,13 @@ func bif_ssub_gssub(input1, input2, input3 *mlrval.Mlrval, doAll bool) *mlrval.M return input3 } if !input1.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError(funcname, input1) } if !input2.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError(funcname, input2) } if !input3.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError(funcname, input3) } if doAll { return mlrval.FromString( @@ -68,13 +68,13 @@ func BIF_sub(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { return input3 } if !input1.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("sub", input1) } if !input2.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("sub", input2) } if !input3.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("sub", input3) } input := input1.AcquireStringValue() @@ -98,13 +98,13 @@ func BIF_gsub(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { return input3 } if !input1.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("gsub", input1) } if !input2.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("gsub", input2) } if !input3.IsStringOrVoid() { - return mlrval.ERROR + return mlrval.FromNotStringError("gsub", input3) } input := input1.AcquireStringValue() @@ -126,7 +126,7 @@ func BIF_string_matches_regexp(input1, input2 *mlrval.Mlrval) (retval *mlrval.Ml } input1string := input1.String() if !input2.IsStringOrVoid() { - return mlrval.ERROR, nil + return mlrval.FromNotStringError("=~", input2), nil } boolOutput, captures := lib.RegexMatches(input1string, input2.AcquireStringValue()) @@ -146,10 +146,10 @@ func BIF_string_does_not_match_regexp(input1, input2 *mlrval.Mlrval) (retval *ml func BIF_regextract(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("!=~", input1) } if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("!=~", input2) } regex := lib.CompileMillerRegexOrDie(input2.AcquireStringValue()) match := regex.FindStringIndex(input1.AcquireStringValue()) @@ -162,10 +162,10 @@ func BIF_regextract(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_regextract_or_else(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("regextract_or_else", input1) } if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("regextract_or_else", input2) } regex := lib.CompileMillerRegexOrDie(input2.AcquireStringValue()) match := regex.FindStringIndex(input1.AcquireStringValue()) diff --git a/internal/pkg/bifs/relative_time.go b/internal/pkg/bifs/relative_time.go index be07c63011..6cd1a9bc33 100644 --- a/internal/pkg/bifs/relative_time.go +++ b/internal/pkg/bifs/relative_time.go @@ -10,7 +10,7 @@ import ( func BIF_dhms2sec(input1 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("dhms2sec", input1) } input := input1.String() @@ -66,7 +66,7 @@ func BIF_dhms2sec(input1 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_dhms2fsec(input1 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("dhms2fsec", input1) } input := input1.String() @@ -122,7 +122,7 @@ func BIF_dhms2fsec(input1 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_hms2sec(input1 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("hms2sec", input1) } if input1.AcquireStringValue() == "" { return mlrval.ERROR @@ -146,7 +146,7 @@ func BIF_hms2sec(input1 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_hms2fsec(input1 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("hms2fsec", input1) } var h, m int @@ -170,7 +170,7 @@ func BIF_hms2fsec(input1 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_sec2dhms(input1 *mlrval.Mlrval) *mlrval.Mlrval { isec, ok := input1.GetIntValue() if !ok { - return mlrval.ERROR + return mlrval.FromNotIntError("sec2dhms", input1) } var d, h, m, s int64 @@ -198,7 +198,7 @@ func BIF_sec2dhms(input1 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_sec2hms(input1 *mlrval.Mlrval) *mlrval.Mlrval { isec, ok := input1.GetIntValue() if !ok { - return mlrval.ERROR + return mlrval.FromNotIntError("sec2hms", input1) } sign := "" if isec < 0 { @@ -219,7 +219,7 @@ func BIF_sec2hms(input1 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_fsec2dhms(input1 *mlrval.Mlrval) *mlrval.Mlrval { fsec, ok := input1.GetNumericToFloatValue() if !ok { - return mlrval.ERROR + return mlrval.FromNotIntError("fsec2dhms", input1) } sign := int64(1) @@ -269,7 +269,7 @@ func BIF_fsec2dhms(input1 *mlrval.Mlrval) *mlrval.Mlrval { func BIF_fsec2hms(input1 *mlrval.Mlrval) *mlrval.Mlrval { fsec, ok := input1.GetNumericToFloatValue() if !ok { - return mlrval.ERROR + return mlrval.FromNotIntError("fsec2hms", input1) } sign := "" diff --git a/internal/pkg/dsl/cst/builtin_functions.go b/internal/pkg/dsl/cst/builtin_functions.go index 44acdfc0fc..1c01dcfba5 100644 --- a/internal/pkg/dsl/cst/builtin_functions.go +++ b/internal/pkg/dsl/cst/builtin_functions.go @@ -908,10 +908,10 @@ func (node *StandardTernaryOperatorNode) Evaluate( func BinaryShortCircuitPlaceholder(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { lib.InternalCodingErrorPanic("Short-circuting was not correctly implemented") - return mlrval.ERROR // not reached + return nil // not reached } func TernaryShortCircuitPlaceholder(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { lib.InternalCodingErrorPanic("Short-circuting was not correctly implemented") - return mlrval.ERROR // not reached + return nil // not reached } diff --git a/internal/pkg/mlrval/mlrval_new.go b/internal/pkg/mlrval/mlrval_new.go index e3ef59ccb0..af2b6f806a 100644 --- a/internal/pkg/mlrval/mlrval_new.go +++ b/internal/pkg/mlrval/mlrval_new.go @@ -101,6 +101,10 @@ func FromNotStringError(funcname string, v *Mlrval) *Mlrval { return FromNotNamedTypeError(funcname, v, "string") } +func FromNotBooleanError(funcname string, v *Mlrval) *Mlrval { + return FromNotNamedTypeError(funcname, v, "boolean") +} + func FromNotIntError(funcname string, v *Mlrval) *Mlrval { return FromNotNamedTypeError(funcname, v, "int") } diff --git a/internal/pkg/transformers/latin1_to_utf8.go b/internal/pkg/transformers/latin1_to_utf8.go index ade2b2b1c5..0783b62794 100644 --- a/internal/pkg/transformers/latin1_to_utf8.go +++ b/internal/pkg/transformers/latin1_to_utf8.go @@ -106,7 +106,7 @@ func (tr *TransformerLatin1ToUTF8) Transform( if err == nil { pe.Value = mlrval.FromString(output) } else { - pe.Value = mlrval.ERROR + pe.Value = mlrval.FromError(err) } } } diff --git a/internal/pkg/transformers/utf8_to_latin1.go b/internal/pkg/transformers/utf8_to_latin1.go index bafed1e59d..e3f09210dc 100644 --- a/internal/pkg/transformers/utf8_to_latin1.go +++ b/internal/pkg/transformers/utf8_to_latin1.go @@ -106,7 +106,7 @@ func (tr *TransformerUTF8ToLatin1) Transform( if err == nil { pe.Value = mlrval.FromString(output) } else { - pe.Value = mlrval.ERROR + pe.Value = mlrval.FromError(err) } } } From ee1ed00014d557420bb3ed1371367a45d01465f3 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 29 Aug 2023 23:27:23 -0400 Subject: [PATCH 15/22] more --- internal/pkg/bifs/collections.go | 6 ++- internal/pkg/bifs/datetime.go | 18 ++++----- internal/pkg/bifs/random.go | 4 +- internal/pkg/dsl/cst/collections.go | 60 ++++++++++++++++++++++++----- internal/pkg/dsl/cst/hofs.go | 32 +++++++-------- internal/pkg/mlrval/mlrval_get.go | 22 ++++++++++- internal/pkg/mlrval/mlrval_new.go | 2 +- 7 files changed, 102 insertions(+), 42 deletions(-) diff --git a/internal/pkg/bifs/collections.go b/internal/pkg/bifs/collections.go index 5d45cd1d4b..5278b5b6a1 100644 --- a/internal/pkg/bifs/collections.go +++ b/internal/pkg/bifs/collections.go @@ -910,7 +910,8 @@ func MillerSliceAccess( if lowerIndexMlrval.IsVoid() { lowerIndex = 1 } else { - return false, mlrval.ERROR, 0, 0 + e := mlrval.FromNotNamedTypeError("array/map/slice lower index", lowerIndexMlrval, "int or empty") + return false, e, 0, 0 } } upperIndex, ok := upperIndexMlrval.GetIntValue() @@ -918,7 +919,8 @@ func MillerSliceAccess( if upperIndexMlrval.IsVoid() { upperIndex = int64(n) } else { - return false, mlrval.ERROR, 0, 0 + e := mlrval.FromNotNamedTypeError("array/map/slice upper index", upperIndexMlrval, "int or empty") + return false, e, 0, 0 } } diff --git a/internal/pkg/bifs/datetime.go b/internal/pkg/bifs/datetime.go index 9ab5d3031f..f1d197785c 100644 --- a/internal/pkg/bifs/datetime.go +++ b/internal/pkg/bifs/datetime.go @@ -62,22 +62,22 @@ func BIF_sec2gmt_unary(input1 *mlrval.Mlrval) *mlrval.Mlrval { } func BIF_nsec2gmt_unary(input1 *mlrval.Mlrval) *mlrval.Mlrval { - intValue, ok := input1.GetIntValue() - if !ok { - return mlrval.ERROR + intValue, errValue := input1.GetIntValueOrError("nsec2gmt") + if errValue != nil { + return errValue } numDecimalPlaces := 0 return mlrval.FromString(lib.Nsec2GMT(intValue, numDecimalPlaces)) } func BIF_sec2gmt_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - floatValue, isNumeric := input1.GetNumericToFloatValue() - if !isNumeric { - return input1 + floatValue, errValue := input1.GetNumericToFloatValueOrError("sec2gmt") + if errValue != nil { + return errValue } - numDecimalPlaces, isInt := input2.GetIntValue() - if !isInt { - return mlrval.ERROR + numDecimalPlaces, errValue := input2.GetIntValueOrError("sec2gmt") + if errValue != nil { + return errValue } return mlrval.FromString(lib.Sec2GMT(floatValue, int(numDecimalPlaces))) } diff --git a/internal/pkg/bifs/random.go b/internal/pkg/bifs/random.go index 41db35e124..5562b4d301 100644 --- a/internal/pkg/bifs/random.go +++ b/internal/pkg/bifs/random.go @@ -62,10 +62,10 @@ func BIF_urandrange(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { a, aok := input1.GetNumericToFloatValue() b, bok := input2.GetNumericToFloatValue() if !aok { - return mlrval.FromNotIntOrFloatError("urandrange", input1) + return mlrval.FromNotNumericError("urandrange", input1) } if !bok { - return mlrval.FromNotIntOrFloatError("urandrange", input2) + return mlrval.FromNotNumericError("urandrange", input2) } return mlrval.FromFloat( a + (b-a)*lib.RandFloat64(), diff --git a/internal/pkg/dsl/cst/collections.go b/internal/pkg/dsl/cst/collections.go index bf117b00ef..66d63788fa 100644 --- a/internal/pkg/dsl/cst/collections.go +++ b/internal/pkg/dsl/cst/collections.go @@ -6,6 +6,8 @@ package cst import ( + "fmt" + "github.com/johnkerl/miller/internal/pkg/bifs" "github.com/johnkerl/miller/internal/pkg/dsl" "github.com/johnkerl/miller/internal/pkg/lib" @@ -97,14 +99,28 @@ func (node *ArrayOrMapIndexAccessNode) Evaluate( } else if baseMlrval.IsStringOrVoid() { mindex, isInt := indexMlrval.GetIntValue() if !isInt { - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf( + "unacceptable non-int index value %s of type %s on base value %s", + indexMlrval.StringMaybeQuoted(), + indexMlrval.GetTypeName(), + baseMlrval.StringMaybeQuoted(), + ), + ) } // Handle UTF-8 correctly: len(input1.printrep) will count bytes, not runes. runes := []rune(baseMlrval.String()) // Miller uses 1-up, and negatively aliased, indexing for strings and arrays. zindex, inBounds := mlrval.UnaliasArrayLengthIndex(len(runes), int(mindex)) if !inBounds { - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf( + "cannot index base string %s of length %d with out-of-bounds index %d", + baseMlrval.StringMaybeQuoted(), + len(runes), + int(mindex), + ), + ) } return mlrval.FromString(string(runes[zindex])) @@ -112,7 +128,13 @@ func (node *ArrayOrMapIndexAccessNode) Evaluate( // For strict mode, absence should be detected on the baseMlrval and indexMlrval evaluators. return mlrval.ABSENT } else { - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf( + "cannot index base value %s of type %s, which is not array, map, or string", + baseMlrval.StringMaybeQuoted(), + baseMlrval.GetTypeName(), + ), + ) } } @@ -171,7 +193,13 @@ func (node *ArraySliceAccessNode) Evaluate( } array := baseMlrval.GetArray() if array == nil { - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf( + "cannot slice base value %s with non-array type %s", + baseMlrval.StringMaybeQuoted(), + baseMlrval.GetTypeName(), + ), + ) } n := len(array) @@ -236,7 +264,7 @@ func (node *PositionalFieldNameNode) Evaluate( index, ok := indexMlrval.GetIntValue() if !ok { - return mlrval.ERROR + return mlrval.FromNotIntError("$[[...]]", indexMlrval) } name, ok := state.Inrec.GetNameAtPositionalIndex(index) @@ -282,7 +310,7 @@ func (node *PositionalFieldValueNode) Evaluate( index, ok := indexMlrval.GetIntValue() if !ok { - return mlrval.ERROR + return mlrval.FromNotIntError("$[[...]]", indexMlrval) } retval := state.Inrec.GetWithPositionalIndex(index) @@ -338,7 +366,7 @@ func (node *ArrayOrMapPositionalNameAccessNode) Evaluate( index, ok := indexMlrval.GetIntValue() if !ok { - return mlrval.ERROR + return mlrval.FromNotIntError("$[[...]]", indexMlrval) } if baseMlrval.IsArray() { @@ -363,7 +391,13 @@ func (node *ArrayOrMapPositionalNameAccessNode) Evaluate( return mlrval.ABSENT } else { - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf( + "cannot index base value %s of type %s, which is not array, map, or string", + baseMlrval.StringMaybeQuoted(), + baseMlrval.GetTypeName(), + ), + ) } } @@ -412,7 +446,7 @@ func (node *ArrayOrMapPositionalValueAccessNode) Evaluate( index, ok := indexMlrval.GetIntValue() if !ok { - return mlrval.ERROR + return mlrval.FromNotIntError("$[[...]]", indexMlrval) } if baseMlrval.IsArray() { @@ -434,7 +468,13 @@ func (node *ArrayOrMapPositionalValueAccessNode) Evaluate( return mlrval.ABSENT } else { - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf( + "cannot index base value %s of type %s, which is not array, map, or string", + baseMlrval.StringMaybeQuoted(), + baseMlrval.GetTypeName(), + ), + ) } } diff --git a/internal/pkg/dsl/cst/hofs.go b/internal/pkg/dsl/cst/hofs.go index b6d710b6cb..9257d7f461 100644 --- a/internal/pkg/dsl/cst/hofs.go +++ b/internal/pkg/dsl/cst/hofs.go @@ -216,7 +216,7 @@ func selectArray( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputArray, errVal := input1.GetArrayOrError("select") + inputArray, errVal := input1.GetArrayValueOrError("select") if inputArray == nil { // not an array return errVal } @@ -252,7 +252,7 @@ func selectMap( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputMap, errVal := input1.GetMapOrError("select") + inputMap, errVal := input1.GetMapValueOrError("select") if inputMap == nil { // not a map return errVal } @@ -307,7 +307,7 @@ func applyArray( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputArray, errVal := input1.GetArrayOrError("apply") + inputArray, errVal := input1.GetArrayValueOrError("apply") if inputArray == nil { return errVal } @@ -334,7 +334,7 @@ func applyMap( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputMap, errVal := input1.GetMapOrError("apply") + inputMap, errVal := input1.GetMapValueOrError("apply") if inputMap == nil { // not a map return errVal } @@ -378,7 +378,7 @@ func reduceArray( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputArray, errVal := input1.GetArrayOrError("reduce") + inputArray, errVal := input1.GetArrayValueOrError("reduce") if inputArray == nil { return errVal } @@ -408,7 +408,7 @@ func reduceMap( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputMap, errVal := input1.GetMapOrError("reduce") + inputMap, errVal := input1.GetMapValueOrError("reduce") if inputMap == nil { // not a map return errVal } @@ -459,7 +459,7 @@ func foldArray( input3 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputArray, errVal := input1.GetArrayOrError("fold") + inputArray, errVal := input1.GetArrayValueOrError("fold") if inputArray == nil { return errVal } @@ -486,7 +486,7 @@ func foldMap( input3 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputMap, errVal := input1.GetMapOrError("fold") + inputMap, errVal := input1.GetMapValueOrError("fold") if inputMap == nil { // not a map return errVal } @@ -602,7 +602,7 @@ func sortA( input1 *mlrval.Mlrval, flags string, ) *mlrval.Mlrval { - temp, errVal := input1.GetArrayOrError("sort") + temp, errVal := input1.GetArrayValueOrError("sort") if temp == nil { // not an array return errVal } @@ -679,7 +679,7 @@ func sortM( input1 *mlrval.Mlrval, flags string, ) *mlrval.Mlrval { - inputMap, errVal := input1.GetMapOrError("sort") + inputMap, errVal := input1.GetMapValueOrError("sort") if inputMap == nil { // not a map return errVal } @@ -840,7 +840,7 @@ func sortAF( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputArray, errVal := input1.GetArrayOrError("select") + inputArray, errVal := input1.GetArrayValueOrError("select") if inputArray == nil { // not an array return errVal } @@ -881,7 +881,7 @@ func sortMF( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputMap, errVal := input1.GetMapOrError("sort") + inputMap, errVal := input1.GetMapValueOrError("sort") if inputMap == nil { // not a map return errVal } @@ -943,7 +943,7 @@ func anyArray( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputArray, errVal := input1.GetArrayOrError("any") + inputArray, errVal := input1.GetArrayValueOrError("any") if inputArray == nil { // not an array return errVal } @@ -979,7 +979,7 @@ func anyMap( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputMap, errVal := input1.GetMapOrError("any") + inputMap, errVal := input1.GetMapValueOrError("any") if inputMap == nil { // not a map return errVal } @@ -1035,7 +1035,7 @@ func everyArray( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputArray, errVal := input1.GetArrayOrError("every") + inputArray, errVal := input1.GetArrayValueOrError("every") if inputArray == nil { // not an array return errVal } @@ -1071,7 +1071,7 @@ func everyMap( input2 *mlrval.Mlrval, state *runtime.State, ) *mlrval.Mlrval { - inputMap, errVal := input1.GetMapOrError("every") + inputMap, errVal := input1.GetMapValueOrError("every") if inputMap == nil { // not a map return errVal } diff --git a/internal/pkg/mlrval/mlrval_get.go b/internal/pkg/mlrval/mlrval_get.go index 68b4b6e5e9..3d0874c2ac 100644 --- a/internal/pkg/mlrval/mlrval_get.go +++ b/internal/pkg/mlrval/mlrval_get.go @@ -31,6 +31,14 @@ func (mv *Mlrval) GetIntValue() (intValue int64, isInt bool) { } } +func (mv *Mlrval) GetIntValueOrError(funcname string) (intValue int64, err *Mlrval) { + if mv.Type() == MT_INT { + return mv.intf.(int64), nil + } else { + return -999, FromNotIntError(funcname, mv) + } +} + func (mv *Mlrval) GetFloatValue() (floatValue float64, isFloat bool) { if mv.Type() == MT_FLOAT { return mv.intf.(float64), true @@ -49,6 +57,16 @@ func (mv *Mlrval) GetNumericToFloatValue() (floatValue float64, isFloat bool) { } } +func (mv *Mlrval) GetNumericToFloatValueOrError(funcname string) (floatValue float64, errValue *Mlrval) { + if mv.Type() == MT_FLOAT { + return mv.intf.(float64), nil + } else if mv.Type() == MT_INT { + return float64(mv.intf.(int64)), nil + } else { + return -888.0, FromNotNumericError(funcname, mv) + } +} + func (mv *Mlrval) GetNumericNegativeorDie() bool { floatValue, ok := mv.GetNumericToFloatValue() lib.InternalCodingErrorIf(!ok) @@ -71,7 +89,7 @@ func (mv *Mlrval) GetArray() []*Mlrval { } } -func (mv *Mlrval) GetArrayOrError(funcname string) (ok []*Mlrval, err *Mlrval) { +func (mv *Mlrval) GetArrayValueOrError(funcname string) (ok []*Mlrval, err *Mlrval) { if mv.IsArray() { return mv.intf.([]*Mlrval), nil } else { @@ -87,7 +105,7 @@ func (mv *Mlrval) GetMap() *Mlrmap { } } -func (mv *Mlrval) GetMapOrError(funcname string) (ok *Mlrmap, err *Mlrval) { +func (mv *Mlrval) GetMapValueOrError(funcname string) (ok *Mlrmap, err *Mlrval) { if mv.IsMap() { return mv.intf.(*Mlrmap), nil } else { diff --git a/internal/pkg/mlrval/mlrval_new.go b/internal/pkg/mlrval/mlrval_new.go index af2b6f806a..474dcb807b 100644 --- a/internal/pkg/mlrval/mlrval_new.go +++ b/internal/pkg/mlrval/mlrval_new.go @@ -109,7 +109,7 @@ func FromNotIntError(funcname string, v *Mlrval) *Mlrval { return FromNotNamedTypeError(funcname, v, "int") } -func FromNotIntOrFloatError(funcname string, v *Mlrval) *Mlrval { +func FromNotNumericError(funcname string, v *Mlrval) *Mlrval { return FromNotNamedTypeError(funcname, v, "int or float") } From 33a0a28411ce96dee5af849eb37d07d919577cc8 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 29 Aug 2023 23:53:49 -0400 Subject: [PATCH 16/22] more --- internal/pkg/bifs/datetime.go | 138 ++++++++++++++++------------- internal/pkg/bifs/relative_time.go | 4 +- internal/pkg/dsl/cst/udf.go | 8 +- internal/pkg/mlrval/mlrval_get.go | 14 ++- 4 files changed, 91 insertions(+), 73 deletions(-) diff --git a/internal/pkg/bifs/datetime.go b/internal/pkg/bifs/datetime.go index f1d197785c..4126078b15 100644 --- a/internal/pkg/bifs/datetime.go +++ b/internal/pkg/bifs/datetime.go @@ -87,9 +87,9 @@ func BIF_nsec2gmt_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !ok { return input1 } - numDecimalPlaces, isInt := input2.GetIntValue() - if !isInt { - return mlrval.ERROR + numDecimalPlaces, errValue := input2.GetIntValueOrError("nsec2gmt") + if errValue != nil { + return errValue } return mlrval.FromString(lib.Nsec2GMT(intValue, int(numDecimalPlaces))) } @@ -117,9 +117,9 @@ func BIF_sec2localtime_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !isNumeric { return input1 } - numDecimalPlaces, isInt := input2.GetIntValue() - if !isInt { - return mlrval.ERROR + numDecimalPlaces, errValue := input2.GetIntValueOrError("sec2localtime") + if errValue != nil { + return errValue } return mlrval.FromString(lib.Sec2LocalTime(floatValue, int(numDecimalPlaces))) } @@ -129,9 +129,9 @@ func BIF_nsec2localtime_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !ok { return input1 } - numDecimalPlaces, isInt := input2.GetIntValue() - if !isInt { - return mlrval.ERROR + numDecimalPlaces, errValue := input2.GetIntValueOrError("nsec2localtime") + if errValue != nil { + return errValue } return mlrval.FromString(lib.Nsec2LocalTime(intValue, int(numDecimalPlaces))) } @@ -141,17 +141,17 @@ func BIF_sec2localtime_ternary(input1, input2, input3 *mlrval.Mlrval) *mlrval.Ml if !isNumeric { return input1 } - numDecimalPlaces, isInt := input2.GetIntValue() - if !isInt { - return mlrval.ERROR + numDecimalPlaces, errValue := input2.GetIntValueOrError("sec2localtime") + if errValue != nil { + return errValue } - locationString, isString := input3.GetStringValue() - if !isString { - return mlrval.ERROR + locationString, errValue := input3.GetStringValueOrError("sec2localtime") + if errValue != nil { + return errValue } location, err := time.LoadLocation(locationString) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } return mlrval.FromString(lib.Sec2LocationTime(floatValue, int(numDecimalPlaces), location)) } @@ -161,17 +161,17 @@ func BIF_nsec2localtime_ternary(input1, input2, input3 *mlrval.Mlrval) *mlrval.M if !isNumeric { return input1 } - numDecimalPlaces, isInt := input2.GetIntValue() - if !isInt { - return mlrval.ERROR + numDecimalPlaces, errValue := input2.GetIntValueOrError("nsec2localtime") + if errValue != nil { + return errValue } - locationString, isString := input3.GetStringValue() - if !isString { - return mlrval.ERROR + locationString, errValue := input3.GetStringValueOrError("nsec2localtime") + if errValue != nil { + return errValue } location, err := time.LoadLocation(locationString) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } return mlrval.FromString(lib.Nsec2LocationTime(intValue, int(numDecimalPlaces), location)) } @@ -221,28 +221,28 @@ func BIF_nsec2localdate_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { // ---------------------------------------------------------------- func BIF_localtime2gmt_unary(input1 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("localtime2gmt", input1) } return BIF_nsec2gmt_unary(BIF_localtime2nsec_unary(input1)) } func BIF_localtime2gmt_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("localtime2gmt", input1) } return BIF_nsec2gmt_unary(BIF_localtime2nsec_binary(input1, input2)) } func BIF_gmt2localtime_unary(input1 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("gmt2localtime2", input1) } return BIF_nsec2localtime_unary(BIF_gmt2nsec(input1)) } func BIF_gmt2localtime_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { if !input1.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("gmt2localtime2", input1) } return BIF_nsec2localtime_ternary(BIF_gmt2nsec(input1), mlrval.FromInt(0), input2) } @@ -254,57 +254,62 @@ func BIF_gmt2localtime_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { var extensionRegex = regexp.MustCompile("([1-9])S") func BIF_strftime(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return strftimeHelper(input1, input2, false, nil) + return strftimeHelper(input1, input2, false, nil, "strftime") } func BIF_strfntime(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return strfntimeHelper(input1, input2, false, nil) + return strfntimeHelper(input1, input2, false, nil, "strfntime") } func BIF_strftime_local_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return strftimeHelper(input1, input2, true, nil) + return strftimeHelper(input1, input2, true, nil, "strftime_local") } func BIF_strfntime_local_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { - return strfntimeHelper(input1, input2, true, nil) + return strfntimeHelper(input1, input2, true, nil, "strfntime_local") } func BIF_strftime_local_ternary(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { - locationString, isString := input3.GetStringValue() - if !isString { - return mlrval.ERROR + locationString, errValue := input3.GetStringValueOrError("strftime") + if errValue != nil { + return errValue } location, err := time.LoadLocation(locationString) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } - return strftimeHelper(input1, input2, true, location) + return strftimeHelper(input1, input2, true, location, "strftime_local") } func BIF_strfntime_local_ternary(input1, input2, input3 *mlrval.Mlrval) *mlrval.Mlrval { - locationString, isString := input3.GetStringValue() - if !isString { - return mlrval.ERROR + locationString, errValue := input3.GetStringValueOrError("strfntime") + if errValue != nil { + return errValue } location, err := time.LoadLocation(locationString) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } - return strfntimeHelper(input1, input2, true, location) + return strfntimeHelper(input1, input2, true, location, "strfntime_local") } -func strftimeHelper(input1, input2 *mlrval.Mlrval, doLocal bool, location *time.Location) *mlrval.Mlrval { +func strftimeHelper( + input1, input2 *mlrval.Mlrval, + doLocal bool, + location *time.Location, + funcname string, +) *mlrval.Mlrval { if input1.IsVoid() { return input1 } - epochSeconds, ok := input1.GetNumericToFloatValue() - if !ok { - return mlrval.ERROR + epochSeconds, errValue := input1.GetNumericToFloatValueOrError(funcname) + if errValue != nil { + return errValue } if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError(funcname, input2) } // Convert argument1 from float seconds since the epoch to a Go time. @@ -329,7 +334,7 @@ func strftimeHelper(input1, input2 *mlrval.Mlrval, doLocal bool, location *time. formatter, err := strftime.New(formatString, strftimeExtensions) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } outputString := formatter.FormatString(inputTime) @@ -337,16 +342,21 @@ func strftimeHelper(input1, input2 *mlrval.Mlrval, doLocal bool, location *time. return mlrval.FromString(outputString) } -func strfntimeHelper(input1, input2 *mlrval.Mlrval, doLocal bool, location *time.Location) *mlrval.Mlrval { +func strfntimeHelper( + input1, input2 *mlrval.Mlrval, + doLocal bool, + location *time.Location, + funcname string, +) *mlrval.Mlrval { if input1.IsVoid() { return input1 } - epochNanoseconds, ok := input1.GetIntValue() - if !ok { - return mlrval.ERROR + epochNanoseconds, errValue := input1.GetIntValueOrError(funcname) + if errValue != nil { + return errValue } if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError(funcname, input2) } // Convert argument1 from float seconds since the epoch to a Go time. @@ -371,7 +381,7 @@ func strfntimeHelper(input1, input2 *mlrval.Mlrval, doLocal bool, location *time formatter, err := strftime.New(formatString, strftimeExtensions) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } outputString := formatter.FormatString(inputTime) @@ -473,10 +483,10 @@ func BIF_strpntime(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { func bif_strptime_unary_aux(input1, input2 *mlrval.Mlrval, doLocal, produceNanoseconds bool) *mlrval.Mlrval { if !input1.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("strptime", input1) } if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("strptime", input2) } timeString := input1.AcquireStringValue() formatString := input2.AcquireStringValue() @@ -489,7 +499,7 @@ func bif_strptime_unary_aux(input1, input2 *mlrval.Mlrval, doLocal, produceNanos t, err = strptime.Parse(timeString, formatString) } if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } if produceNanoseconds { @@ -529,10 +539,10 @@ func BIF_strpntime_local_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { func bif_strptime_binary_aux(input1, input2 *mlrval.Mlrval, doLocal, produceNanoseconds bool) *mlrval.Mlrval { if !input1.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("strptime", input1) } if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("strptime", input2) } timeString := input1.AcquireStringValue() formatString := input2.AcquireStringValue() @@ -545,7 +555,7 @@ func bif_strptime_binary_aux(input1, input2 *mlrval.Mlrval, doLocal, produceNano t, err = strptime.Parse(timeString, formatString) } if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } if produceNanoseconds { @@ -575,13 +585,13 @@ func BIF_localtime2nsec_binary(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { func bif_strptime_local_ternary_aux(input1, input2, input3 *mlrval.Mlrval, produceNanoseconds bool) *mlrval.Mlrval { if !input1.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("strptime_local", input1) } if !input2.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("strptime_local", input2) } if !input3.IsString() { - return mlrval.ERROR + return mlrval.FromNotStringError("strptime_local", input3) } timeString := input1.AcquireStringValue() @@ -590,12 +600,12 @@ func bif_strptime_local_ternary_aux(input1, input2, input3 *mlrval.Mlrval, produ location, err := time.LoadLocation(locationString) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } t, err := strptime.ParseLocation(timeString, formatString, location) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } if produceNanoseconds { diff --git a/internal/pkg/bifs/relative_time.go b/internal/pkg/bifs/relative_time.go index 6cd1a9bc33..9c39780f9b 100644 --- a/internal/pkg/bifs/relative_time.go +++ b/internal/pkg/bifs/relative_time.go @@ -36,7 +36,7 @@ func BIF_dhms2sec(input1 *mlrval.Mlrval) *mlrval.Mlrval { _, err := fmt.Sscanf(remainingInput, "%d%s", &n, &rest) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } if len(rest) < 1 { return mlrval.ERROR @@ -92,7 +92,7 @@ func BIF_dhms2fsec(input1 *mlrval.Mlrval) *mlrval.Mlrval { _, err := fmt.Sscanf(remainingInput, "%f%s", &f, &rest) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } if len(rest) < 1 { return mlrval.ERROR diff --git a/internal/pkg/dsl/cst/udf.go b/internal/pkg/dsl/cst/udf.go index aafc2bd1b3..83c1a5b091 100644 --- a/internal/pkg/dsl/cst/udf.go +++ b/internal/pkg/dsl/cst/udf.go @@ -250,12 +250,12 @@ func (site *UDFCallsite) EvaluateWithArguments( // being MT_ERROR should be mapped to MT_ERROR here (nominally, // data-dependent). But error-return could be something not data-dependent. if err != nil { - err = udf.signature.typeGatedReturnValue.Check(mlrval.ERROR) - if err != nil { - fmt.Fprint(os.Stderr, err) + err2 := udf.signature.typeGatedReturnValue.Check(mlrval.FromError(err)) + if err2 != nil { + fmt.Fprint(os.Stderr, err2) os.Exit(1) } - return mlrval.ERROR + return mlrval.FromError(err) } // Fell off end of function with no return diff --git a/internal/pkg/mlrval/mlrval_get.go b/internal/pkg/mlrval/mlrval_get.go index 3d0874c2ac..c88d8d36a4 100644 --- a/internal/pkg/mlrval/mlrval_get.go +++ b/internal/pkg/mlrval/mlrval_get.go @@ -23,6 +23,14 @@ func (mv *Mlrval) GetStringValue() (stringValue string, isString bool) { } } +func (mv *Mlrval) GetStringValueOrError(funcname string) (stringValue string, errValue *Mlrval) { + if mv.Type() == MT_STRING || mv.Type() == MT_VOID { + return mv.printrep, nil + } else { + return "", FromNotStringError(funcname, mv) + } +} + func (mv *Mlrval) GetIntValue() (intValue int64, isInt bool) { if mv.Type() == MT_INT { return mv.intf.(int64), true @@ -31,7 +39,7 @@ func (mv *Mlrval) GetIntValue() (intValue int64, isInt bool) { } } -func (mv *Mlrval) GetIntValueOrError(funcname string) (intValue int64, err *Mlrval) { +func (mv *Mlrval) GetIntValueOrError(funcname string) (intValue int64, errValue *Mlrval) { if mv.Type() == MT_INT { return mv.intf.(int64), nil } else { @@ -89,7 +97,7 @@ func (mv *Mlrval) GetArray() []*Mlrval { } } -func (mv *Mlrval) GetArrayValueOrError(funcname string) (ok []*Mlrval, err *Mlrval) { +func (mv *Mlrval) GetArrayValueOrError(funcname string) (ok []*Mlrval, errValue *Mlrval) { if mv.IsArray() { return mv.intf.([]*Mlrval), nil } else { @@ -105,7 +113,7 @@ func (mv *Mlrval) GetMap() *Mlrmap { } } -func (mv *Mlrval) GetMapValueOrError(funcname string) (ok *Mlrmap, err *Mlrval) { +func (mv *Mlrval) GetMapValueOrError(funcname string) (ok *Mlrmap, errValue *Mlrval) { if mv.IsMap() { return mv.intf.(*Mlrmap), nil } else { From 038ac2bce8da8a56fec095aeb6252c7bfde95311 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Wed, 30 Aug 2023 13:39:21 -0400 Subject: [PATCH 17/22] more --- internal/pkg/bifs/relative_time.go | 34 +++++++++++++++++------ internal/pkg/bifs/strings.go | 33 ++++++++++++++++------ internal/pkg/dsl/cst/builtin_functions.go | 10 +++---- internal/pkg/mlrval/mlrmap_json.go | 4 +-- internal/pkg/mlrval/mlrval_cmp_test.go | 2 +- internal/pkg/mlrval/mlrval_collections.go | 10 +++---- internal/pkg/mlrval/mlrval_constants.go | 6 ---- internal/pkg/mlrval/mlrval_is_test.go | 18 ++++++------ internal/pkg/mlrval/mlrval_sort_test.go | 14 +++++----- xtodo.txt | 10 ++----- 10 files changed, 81 insertions(+), 60 deletions(-) diff --git a/internal/pkg/bifs/relative_time.go b/internal/pkg/bifs/relative_time.go index 9c39780f9b..d6d57b16a9 100644 --- a/internal/pkg/bifs/relative_time.go +++ b/internal/pkg/bifs/relative_time.go @@ -15,7 +15,7 @@ func BIF_dhms2sec(input1 *mlrval.Mlrval) *mlrval.Mlrval { input := input1.String() if input == "" { - return mlrval.ERROR + return mlrval.FromNotStringError("dhms2sec", input1) } negate := false @@ -39,7 +39,7 @@ func BIF_dhms2sec(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromError(err) } if len(rest) < 1 { - return mlrval.ERROR + return mlrval.FromErrorString("dhms2sec: input too short") } unitPart := rest[0] remainingInput = rest[1:] @@ -54,7 +54,13 @@ func BIF_dhms2sec(input1 *mlrval.Mlrval) *mlrval.Mlrval { case 's': seconds += n default: - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf( + "dhms2sec(\"%s\"): unrecognized unit '%c'", + input1.OriginalString(), + unitPart, + ), + ) } } if negate { @@ -71,7 +77,7 @@ func BIF_dhms2fsec(input1 *mlrval.Mlrval) *mlrval.Mlrval { input := input1.String() if input == "" { - return mlrval.ERROR + return mlrval.FromNotStringError("dhms2fsec", input1) } negate := false @@ -95,7 +101,7 @@ func BIF_dhms2fsec(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromError(err) } if len(rest) < 1 { - return mlrval.ERROR + return mlrval.FromErrorString("dhms2fsec: input too short") } unitPart := rest[0] remainingInput = rest[1:] @@ -110,7 +116,13 @@ func BIF_dhms2fsec(input1 *mlrval.Mlrval) *mlrval.Mlrval { case 's': seconds += f default: - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf( + "dhms2fsec(\"%s\"): unrecognized unit '%c'", + input1.OriginalString(), + unitPart, + ), + ) } } if negate { @@ -125,7 +137,7 @@ func BIF_hms2sec(input1 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.FromNotStringError("hms2sec", input1) } if input1.AcquireStringValue() == "" { - return mlrval.ERROR + return mlrval.FromNotStringError("hms2sec", input1) } var h, m, s int64 @@ -141,7 +153,9 @@ func BIF_hms2sec(input1 *mlrval.Mlrval) *mlrval.Mlrval { } } - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf("hsm2sec: could not parse input \"%s\"", input1.OriginalString()), + ) } func BIF_hms2fsec(input1 *mlrval.Mlrval) *mlrval.Mlrval { @@ -164,7 +178,9 @@ func BIF_hms2fsec(input1 *mlrval.Mlrval) *mlrval.Mlrval { } } - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf("hsm2fsec: could not parse input \"%s\"", input1.OriginalString()), + ) } func BIF_sec2dhms(input1 *mlrval.Mlrval) *mlrval.Mlrval { diff --git a/internal/pkg/bifs/strings.go b/internal/pkg/bifs/strings.go index 8a99277c32..7ef8019a47 100644 --- a/internal/pkg/bifs/strings.go +++ b/internal/pkg/bifs/strings.go @@ -2,6 +2,7 @@ package bifs import ( "bytes" + "fmt" "regexp" "strconv" "strings" @@ -161,7 +162,7 @@ func BIF_contains(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { return mlrval.ABSENT } if input1.IsError() { - return mlrval.ERROR + return input1 } return mlrval.FromBool(strings.Contains(input1.String(), input2.String())) @@ -426,7 +427,15 @@ func bif_unformat_aux(input1, input2 *mlrval.Mlrval, inferTypes bool) *mlrval.Ml remaining := input if !strings.HasPrefix(remaining, templatePieces[0]) { - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf( + "unformat(\"%s\", \"%s\"): component \"%s\" lacks prefix \"%s\"", + input1.OriginalString(), + input2.OriginalString(), + remaining, + templatePieces[0], + ), + ) } remaining = remaining[len(templatePieces[0]):] templatePieces = templatePieces[1:] @@ -442,7 +451,15 @@ func bif_unformat_aux(input1, input2 *mlrval.Mlrval, inferTypes bool) *mlrval.Ml } else { index = strings.Index(remaining, templatePiece) if index < 0 { - return mlrval.ERROR + return mlrval.FromError( + fmt.Errorf( + "unformat(\"%s\", \"%s\"): component \"%s\" lacks prefix \"%s\"", + input1.OriginalString(), + input2.OriginalString(), + remaining, + templatePiece, + ), + ) } } @@ -475,7 +492,7 @@ func fmtnum_is(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { formatString := input2.AcquireStringValue() formatter, err := mlrval.GetFormatter(formatString) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } return formatter.Format(input1) @@ -488,7 +505,7 @@ func fmtnum_fs(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { formatString := input2.AcquireStringValue() formatter, err := mlrval.GetFormatter(formatString) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } return formatter.Format(input1) @@ -501,7 +518,7 @@ func fmtnum_bs(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval { formatString := input2.AcquireStringValue() formatter, err := mlrval.GetFormatter(formatString) if err != nil { - return mlrval.ERROR + return mlrval.FromError(err) } intMv := mlrval.FromInt(lib.BoolToInt(input1.AcquireBoolValue())) @@ -557,7 +574,7 @@ func BIF_latin1_to_utf8(input1 *mlrval.Mlrval) *mlrval.Mlrval { if err != nil { // Somewhat arbitrary design decision // return input1 - return mlrval.ERROR + return mlrval.FromError(err) } else { return mlrval.FromString(output) } @@ -574,7 +591,7 @@ func BIF_utf8_to_latin1(input1 *mlrval.Mlrval) *mlrval.Mlrval { if err != nil { // Somewhat arbitrary design decision // return input1 - return mlrval.ERROR + return mlrval.FromError(err) } else { return mlrval.FromString(output) } diff --git a/internal/pkg/dsl/cst/builtin_functions.go b/internal/pkg/dsl/cst/builtin_functions.go index 1c01dcfba5..dfc1b45966 100644 --- a/internal/pkg/dsl/cst/builtin_functions.go +++ b/internal/pkg/dsl/cst/builtin_functions.go @@ -752,7 +752,7 @@ func (node *LogicalANDOperatorNode) Evaluate( aout := node.a.Evaluate(state) atype := aout.Type() if !(atype == mlrval.MT_ABSENT || atype == mlrval.MT_BOOL) { - return mlrval.ERROR + return mlrval.FromNotNamedTypeError("&&", aout, "absent or boolean") } if atype == mlrval.MT_ABSENT { return mlrval.ABSENT @@ -768,7 +768,7 @@ func (node *LogicalANDOperatorNode) Evaluate( bout := node.b.Evaluate(state) btype := bout.Type() if !(btype == mlrval.MT_ABSENT || btype == mlrval.MT_BOOL) { - return mlrval.ERROR + return mlrval.FromNotNamedTypeError("&&", bout, "absent or boolean") } if btype == mlrval.MT_ABSENT { return mlrval.ABSENT @@ -800,7 +800,7 @@ func (node *LogicalOROperatorNode) Evaluate( aout := node.a.Evaluate(state) atype := aout.Type() if !(atype == mlrval.MT_ABSENT || atype == mlrval.MT_BOOL) { - return mlrval.ERROR + return mlrval.FromNotNamedTypeError("||", aout, "absent or boolean") } if atype == mlrval.MT_ABSENT { return mlrval.ABSENT @@ -816,7 +816,7 @@ func (node *LogicalOROperatorNode) Evaluate( bout := node.b.Evaluate(state) btype := bout.Type() if !(btype == mlrval.MT_ABSENT || btype == mlrval.MT_BOOL) { - return mlrval.ERROR + return mlrval.FromNotNamedTypeError("||", bout, "absent or boolean") } if btype == mlrval.MT_ABSENT { return mlrval.ABSENT @@ -884,7 +884,7 @@ func (node *StandardTernaryOperatorNode) Evaluate( boolValue, isBool := aout.GetBoolValue() if !isBool { - return mlrval.ERROR + return mlrval.FromNotBooleanError("?:", aout) } // Short-circuit: defer evaluation unless needed diff --git a/internal/pkg/mlrval/mlrmap_json.go b/internal/pkg/mlrval/mlrmap_json.go index 7b2628ed72..726c38fb71 100644 --- a/internal/pkg/mlrval/mlrmap_json.go +++ b/internal/pkg/mlrval/mlrmap_json.go @@ -153,7 +153,7 @@ func (entry *MlrmapEntry) JSONStringifyInPlace( ) { outputBytes, err := entry.Value.MarshalJSON(jsonFormatting, false) if err != nil { - entry.Value = ERROR + entry.Value = FromError(err) } else { entry.Value = FromString(string(outputBytes)) } @@ -165,7 +165,7 @@ func (entry *MlrmapEntry) JSONParseInPlace() { input := entry.Value.String() err := entry.Value.UnmarshalJSON([]byte(input)) if err != nil { - entry.Value = ERROR + entry.Value = FromError(err) } } diff --git a/internal/pkg/mlrval/mlrval_cmp_test.go b/internal/pkg/mlrval/mlrval_cmp_test.go index 0700f87152..1510834492 100644 --- a/internal/pkg/mlrval/mlrval_cmp_test.go +++ b/internal/pkg/mlrval/mlrval_cmp_test.go @@ -34,7 +34,7 @@ var orderedMlrvals = []*Mlrval{ // FromMap(NewMlrmap()), // TODO: - ERROR, + FromErrorString("error text goes here"), NULL, ABSENT, } diff --git a/internal/pkg/mlrval/mlrval_collections.go b/internal/pkg/mlrval/mlrval_collections.go index 5e009aff29..1e33b552bb 100644 --- a/internal/pkg/mlrval/mlrval_collections.go +++ b/internal/pkg/mlrval/mlrval_collections.go @@ -81,10 +81,10 @@ import ( // TODO: copy-reduction refactor func (mv *Mlrval) ArrayGet(mindex *Mlrval) Mlrval { if !mv.IsArray() { - return *ERROR + return *FromNotArrayError("array [] base", mv) } if !mindex.IsInt() { - return *ERROR + return *FromNotIntError("array [] index", mindex) } arrayval := mv.intf.([]*Mlrval) value := arrayGetAliased(&arrayval, int(mindex.intf.(int64))) @@ -223,12 +223,12 @@ func (mv *Mlrval) ArrayAppend(value *Mlrval) { // ================================================================ func (mv *Mlrval) MapGet(key *Mlrval) Mlrval { if !mv.IsMap() { - return *ERROR + return *FromNotMapError("map[]", mv) } mval, err := mv.intf.(*Mlrmap).GetWithMlrvalIndex(key) - if err != nil { // xxx maybe error-return in the API - return *ERROR + if err != nil { + return *FromError(err) } if mval == nil { return *ABSENT diff --git a/internal/pkg/mlrval/mlrval_constants.go b/internal/pkg/mlrval/mlrval_constants.go index 3cc09d98e8..d54e119c85 100644 --- a/internal/pkg/mlrval/mlrval_constants.go +++ b/internal/pkg/mlrval/mlrval_constants.go @@ -41,12 +41,6 @@ var VOID = &Mlrval{ printrepValid: true, } -var ERROR = &Mlrval{ - mvtype: MT_ERROR, - printrep: ERROR_PRINTREP, - printrepValid: true, -} - var NULL = &Mlrval{ mvtype: MT_NULL, printrep: "null", diff --git a/internal/pkg/mlrval/mlrval_is_test.go b/internal/pkg/mlrval/mlrval_is_test.go index 47c14fffe5..d3f1834036 100644 --- a/internal/pkg/mlrval/mlrval_is_test.go +++ b/internal/pkg/mlrval/mlrval_is_test.go @@ -11,7 +11,7 @@ import ( ) func TestIsLegit(t *testing.T) { - assert.False(t, ERROR.IsLegit()) + assert.False(t, FromErrorString("foo").IsLegit()) assert.False(t, ABSENT.IsLegit()) assert.False(t, NULL.IsLegit()) assert.True(t, FromString("").IsLegit()) @@ -24,35 +24,35 @@ func TestIsLegit(t *testing.T) { } func TestIsErrorOrAbsent(t *testing.T) { - assert.True(t, ERROR.IsErrorOrAbsent()) + assert.True(t, FromErrorString("foo").IsErrorOrAbsent()) assert.True(t, ABSENT.IsErrorOrAbsent()) assert.False(t, NULL.IsErrorOrAbsent()) assert.False(t, FromString("").IsErrorOrAbsent()) } func TestIsError(t *testing.T) { - assert.True(t, ERROR.IsError()) + assert.True(t, FromErrorString("foo").IsError()) assert.False(t, ABSENT.IsError()) assert.False(t, NULL.IsError()) assert.False(t, FromString("").IsError()) } func TestIsAbsent(t *testing.T) { - assert.False(t, ERROR.IsAbsent()) + assert.False(t, FromErrorString("foo").IsAbsent()) assert.True(t, ABSENT.IsAbsent()) assert.False(t, NULL.IsAbsent()) assert.False(t, FromString("").IsAbsent()) } func TestIsNull(t *testing.T) { - assert.False(t, ERROR.IsNull()) + assert.False(t, FromErrorString("foo").IsNull()) assert.False(t, ABSENT.IsNull()) assert.True(t, NULL.IsNull()) assert.False(t, FromString("").IsNull()) } func TestIsVoid(t *testing.T) { - assert.False(t, ERROR.IsVoid()) + assert.False(t, FromErrorString("foo").IsVoid()) assert.False(t, ABSENT.IsVoid()) assert.False(t, NULL.IsVoid()) assert.True(t, FromString("").IsVoid()) @@ -63,7 +63,7 @@ func TestIsVoid(t *testing.T) { } func TestIsEmptyString(t *testing.T) { - assert.False(t, ERROR.IsEmptyString()) + assert.False(t, FromErrorString("foo").IsEmptyString()) assert.False(t, ABSENT.IsEmptyString()) assert.False(t, NULL.IsEmptyString()) assert.True(t, FromString("").IsEmptyString()) @@ -74,7 +74,7 @@ func TestIsEmptyString(t *testing.T) { } func TestIsString(t *testing.T) { - assert.False(t, ERROR.IsString()) + assert.False(t, FromErrorString("foo").IsString()) assert.False(t, ABSENT.IsString()) assert.False(t, NULL.IsString()) assert.False(t, FromString("").IsString()) @@ -89,7 +89,7 @@ func TestIsString(t *testing.T) { } func TestIsStringOrVoid(t *testing.T) { - assert.False(t, ERROR.IsStringOrVoid()) + assert.False(t, FromErrorString("foo").IsStringOrVoid()) assert.False(t, ABSENT.IsStringOrVoid()) assert.False(t, NULL.IsStringOrVoid()) assert.True(t, FromString("").IsStringOrVoid()) diff --git a/internal/pkg/mlrval/mlrval_sort_test.go b/internal/pkg/mlrval/mlrval_sort_test.go index 8cf515346d..7af350c7e6 100644 --- a/internal/pkg/mlrval/mlrval_sort_test.go +++ b/internal/pkg/mlrval/mlrval_sort_test.go @@ -37,7 +37,7 @@ func TestComparators(t *testing.T) { assert.Equal(t, 0, LexicalAscendingComparator(bfalse, bfalse)) assert.Equal(t, -1, LexicalAscendingComparator(bfalse, btrue)) assert.Equal(t, -1, LexicalAscendingComparator(sabc, sdef)) - assert.Equal(t, 0, LexicalAscendingComparator(ERROR, ERROR)) + assert.Equal(t, 0, LexicalAscendingComparator(FromErrorString("foo"), FromErrorString("foo"))) assert.Equal(t, 0, LexicalAscendingComparator(ABSENT, ABSENT)) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -48,7 +48,7 @@ func TestComparators(t *testing.T) { assert.Equal(t, 1, NumericAscendingComparator(btrue, bfalse)) - assert.Equal(t, 0, NumericAscendingComparator(ERROR, ERROR)) + assert.Equal(t, 0, NumericAscendingComparator(FromErrorString("foo"), FromErrorString("foo"))) assert.Equal(t, 0, NumericAscendingComparator(ABSENT, ABSENT)) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -56,22 +56,22 @@ func TestComparators(t *testing.T) { assert.Equal(t, -1, LexicalAscendingComparator(i10, btrue)) // "10" < "true" assert.Equal(t, -1, LexicalAscendingComparator(i10, sabc)) // "10" < "abc" - assert.Equal(t, 1, LexicalAscendingComparator(i10, ERROR)) // "10" > "(error)" + assert.Equal(t, 1, LexicalAscendingComparator(i10, FromErrorString("foo"))) // "10" > "(error)" assert.Equal(t, 1, LexicalAscendingComparator(bfalse, sabc)) // "false" > "abc" - assert.Equal(t, 1, LexicalAscendingComparator(bfalse, ERROR)) // "false" > "(error)" + assert.Equal(t, 1, LexicalAscendingComparator(bfalse, FromErrorString("foo"))) // "false" > "(error)" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Across-type numeric comparisons assert.Equal(t, -1, NumericAscendingComparator(i10, btrue)) assert.Equal(t, -1, NumericAscendingComparator(i10, sabc)) - assert.Equal(t, -1, NumericAscendingComparator(i10, ERROR)) + assert.Equal(t, -1, NumericAscendingComparator(i10, FromErrorString("foo"))) assert.Equal(t, -1, NumericAscendingComparator(i10, ABSENT)) assert.Equal(t, -1, NumericAscendingComparator(bfalse, sabc)) - assert.Equal(t, -1, NumericAscendingComparator(bfalse, ERROR)) + assert.Equal(t, -1, NumericAscendingComparator(bfalse, FromErrorString("foo"))) assert.Equal(t, -1, NumericAscendingComparator(bfalse, ABSENT)) - assert.Equal(t, -1, NumericAscendingComparator(ERROR, ABSENT)) + assert.Equal(t, -1, NumericAscendingComparator(FromErrorString("foo"), ABSENT)) } diff --git a/xtodo.txt b/xtodo.txt index fb8174bd89..646c4ec146 100644 --- a/xtodo.txt +++ b/xtodo.txt @@ -1,14 +1,8 @@ ---------------------------------------------------------------- -* _erro and _erro1 rid entirely of -* other modules obv ... long and winding road ... * optional env var: MLR_DATA_ERROR_FAIL_FAST or somesuch * maybe call it data-processing error to differentiate from input-data error -- ? * look at: mr -vvv test/cases/io-spec-tsv/0004/cmd -grep -c mlrval.ERROR $(rg -wl mlrval.ERROR|sort) - -mlr -x --from x --csv fraction -f c - ---------------------------------------------------------------- func (keeper *PercentileKeeper) EmitNamed(name string) *mlrval.Mlrval { @@ -51,7 +45,7 @@ func (keeper *PercentileKeeper) EmitNamed(name string) *mlrval.Mlrval { } } else if name == "uif" { - p75 := keeper.EmitNonInterpolated(25.0) + p75 := keeper.EmitNonInterpolated(75.0) iqr := keeper.EmitNamed("iqr") if p75.IsNumeric() && iqr.IsNumeric() { return bifs.BIF_plus_binary(p75, bifs.BIF_times(fenceInnerK, iqr)) @@ -60,7 +54,7 @@ func (keeper *PercentileKeeper) EmitNamed(name string) *mlrval.Mlrval { } } else if name == "uof" { - p75 := keeper.EmitNonInterpolated(25.0) + p75 := keeper.EmitNonInterpolated(75.0) iqr := keeper.EmitNamed("iqr") if p75.IsNumeric() && iqr.IsNumeric() { return bifs.BIF_plus_binary(p75, bifs.BIF_times(fenceOuterK, iqr)) From af59eb264a6fe1e95e512b191cb4f1cbc48b8efd Mon Sep 17 00:00:00 2001 From: John Kerl Date: Wed, 30 Aug 2023 14:39:24 -0400 Subject: [PATCH 18/22] renames --- internal/pkg/cli/option_parse.go | 2 +- internal/pkg/cli/option_types.go | 2 +- internal/pkg/climain/mlrcli_parse.go | 4 ++++ internal/pkg/output/channel_writer.go | 10 +++++----- internal/pkg/stream/stream.go | 6 +++--- xtodo.txt | 2 +- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/internal/pkg/cli/option_parse.go b/internal/pkg/cli/option_parse.go index 8bd7db122e..013deb5822 100644 --- a/internal/pkg/cli/option_parse.go +++ b/internal/pkg/cli/option_parse.go @@ -2715,7 +2715,7 @@ var MiscFlagSection = FlagSection{ name: "-x", help: "If any record has an error value in it, report it and stop the process. The default is to print the field value as `(error)` and continue.", parser: func(args []string, argc int, pargi *int, options *TOptions) { - options.WriterOptions.FatalOnErrorData = true + options.WriterOptions.FailOnDataError = true *pargi += 1 }, }, diff --git a/internal/pkg/cli/option_types.go b/internal/pkg/cli/option_types.go index 96ff3983af..b70d4a2f7f 100644 --- a/internal/pkg/cli/option_types.go +++ b/internal/pkg/cli/option_types.go @@ -137,7 +137,7 @@ type TWriterOptions struct { FPOFMT string // Fatal the process when error data in a given record is about to be output. - FatalOnErrorData bool + FailOnDataError bool } // ---------------------------------------------------------------- diff --git a/internal/pkg/climain/mlrcli_parse.go b/internal/pkg/climain/mlrcli_parse.go index 31e72408f3..e68b5902ed 100644 --- a/internal/pkg/climain/mlrcli_parse.go +++ b/internal/pkg/climain/mlrcli_parse.go @@ -261,6 +261,10 @@ func parseCommandLinePassTwo( options.WriterOptions.FPOFMT = mlr_ofmt } + if os.Getenv("MLR_FAIL_ON_DATA_ERROR") != "" { + options.WriterOptions.FailOnDataError = true + } + recordTransformers = make([]transformers.IRecordTransformer, 0) err = nil ignoresInput := false diff --git a/internal/pkg/output/channel_writer.go b/internal/pkg/output/channel_writer.go index e00e094b4b..ea7ed814d1 100644 --- a/internal/pkg/output/channel_writer.go +++ b/internal/pkg/output/channel_writer.go @@ -15,7 +15,7 @@ func ChannelWriter( recordWriter IRecordWriter, writerOptions *cli.TWriterOptions, doneChannel chan<- bool, - erroredChannel chan<- bool, + dataProcessingErrorChannel chan<- bool, bufferedOutputStream *bufio.Writer, outputIsStdout bool, ) { @@ -26,12 +26,12 @@ func ChannelWriter( recordsAndContexts, recordWriter, writerOptions, - erroredChannel, + dataProcessingErrorChannel, bufferedOutputStream, outputIsStdout, ) if errored { - erroredChannel <- true + dataProcessingErrorChannel <- true doneChannel <- true break } @@ -48,7 +48,7 @@ func channelWriterHandleBatch( recordsAndContexts *list.List, recordWriter IRecordWriter, writerOptions *cli.TWriterOptions, - erroredChannel chan<- bool, + dataProcessingErrorChannel chan<- bool, bufferedOutputStream *bufio.Writer, outputIsStdout bool, ) (done bool, errored bool) { @@ -69,7 +69,7 @@ func channelWriterHandleBatch( // XXX more // XXX also make sure this results in exit 1 & goroutine cleanup - if writerOptions.FatalOnErrorData { + if writerOptions.FailOnDataError { ok := true for pe := record.Head; pe != nil; pe = pe.Next { if pe.Value.IsError() { diff --git a/internal/pkg/stream/stream.go b/internal/pkg/stream/stream.go index 933fb7d704..351eda06dd 100644 --- a/internal/pkg/stream/stream.go +++ b/internal/pkg/stream/stream.go @@ -70,7 +70,7 @@ func Stream( // channels to communicate both of these conditions. inputErrorChannel := make(chan error, 1) doneWritingChannel := make(chan bool, 1) - erroredWritingChannel := make(chan bool, 1) + dataProcessingErrorChannel := make(chan bool, 1) // For mlr head, so a transformer can communicate it will disregard all // further input. It writes this back upstream, and that is passed back to @@ -87,7 +87,7 @@ func Stream( go transformers.ChainTransformer(readerChannel, readerDownstreamDoneChannel, recordTransformers, writerChannel, options) go output.ChannelWriter(writerChannel, recordWriter, &options.WriterOptions, doneWritingChannel, - erroredWritingChannel, bufferedOutputStream, outputIsStdout) + dataProcessingErrorChannel, bufferedOutputStream, outputIsStdout) var retval error done := false @@ -96,7 +96,7 @@ func Stream( case ierr := <-inputErrorChannel: retval = ierr break - case _ = <-erroredWritingChannel: + case _ = <-dataProcessingErrorChannel: retval = errors.New("exiting due to data error") // details already printed break case _ = <-doneWritingChannel: diff --git a/xtodo.txt b/xtodo.txt index 646c4ec146..ff25ea45e4 100644 --- a/xtodo.txt +++ b/xtodo.txt @@ -1,7 +1,7 @@ ---------------------------------------------------------------- * optional env var: MLR_DATA_ERROR_FAIL_FAST or somesuch -* maybe call it data-processing error to differentiate from input-data error -- ? * look at: mr -vvv test/cases/io-spec-tsv/0004/cmd +* doc page w/ options incl .mlrrc ---------------------------------------------------------------- From 3807c65e962b1238529dbb89fc97ce66b93b7dce Mon Sep 17 00:00:00 2001 From: John Kerl Date: Wed, 30 Aug 2023 19:00:51 -0400 Subject: [PATCH 19/22] doc page --- docs/src/data-error.csv | 6 ++++ docs/src/record-heterogeneity.md | 2 ++ docs/src/reference-dsl-errors.md | 51 ++++++++++++++++++++++++++++ docs/src/reference-dsl-errors.md.in | 26 +++++++++++++- docs/src/reference-main-flag-list.md | 1 + xtodo.txt | 2 -- 6 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 docs/src/data-error.csv diff --git a/docs/src/data-error.csv b/docs/src/data-error.csv new file mode 100644 index 0000000000..cc9b52390d --- /dev/null +++ b/docs/src/data-error.csv @@ -0,0 +1,6 @@ +x +1 +2 +3 +text +4 diff --git a/docs/src/record-heterogeneity.md b/docs/src/record-heterogeneity.md index ba80fc3c09..5794fc49a3 100644 --- a/docs/src/record-heterogeneity.md +++ b/docs/src/record-heterogeneity.md @@ -127,6 +127,8 @@ If you `mlr --csv cat` this, you'll get an error message: mlr --csv cat data/het/ragged.csv
+a,b,c
+1,2,3
 mlr: mlr: CSV header/data length mismatch 3 != 2 at filename data/het/ragged.csv row 3.
 .
 
diff --git a/docs/src/reference-dsl-errors.md b/docs/src/reference-dsl-errors.md index 872e7fcd90..7755284c56 100644 --- a/docs/src/reference-dsl-errors.md +++ b/docs/src/reference-dsl-errors.md @@ -16,6 +16,55 @@ Quick links: # DSL errors and transparency +# Handling for data errors + +By default, Miller doesn't stop data processing for a single cell error. For example: + +
+mlr --csv --from data-error.csv cat
+
+
+x
+1
+2
+3
+text
+4
+
+ +
+mlr --csv --from data-error.csv put '$y = log10($x)'
+
+
+x,y
+1,0
+2,0.3010299956639812
+3,0.4771212547196624
+text,(error)
+4,0.6020599913279624
+
+ +If you do want to stop processing, though, you have three options. The first is the `mlr -x` flag: + +
+mlr -x --csv --from data-error.csv put '$y = log10($x)'
+
+
+x,y
+1,0
+2,0.3010299956639812
+3,0.4771212547196624
+mlr: data error at NR=4 FNR=4 FILENAME=data-error.csv
+mlr: field y: log10: unacceptable type string with value "text"
+mlr: exiting due to data error.
+
+ +The second is to put `-x` into your [`~/.mlrrc file`](customization.md). + +The third is to set the `MLR_FAIL_ON_DATA_ERROR` environment variable, which makes `-x` implicit. + +# Common causes of syntax errors + As soon as you have a [programming language](miller-programming-language.md), you start having the problem *What is my code doing, and why?* This includes getting syntax errors -- which are always annoying -- as well as the even more annoying problem of a program which parses without syntax error but doesn't do what you expect. The syntax-error message gives you line/column position for the syntax that couldn't be parsed. The cause may be clear from that information, or perhaps not. Here are some common causes of syntax errors: @@ -26,6 +75,8 @@ The syntax-error message gives you line/column position for the syntax that coul * Curly braces are required for the bodies of `if`/`while`/`for` blocks, even when the body is a single statement. +# Transparency + As for transparency: * As in any language, you can do `print`, or `eprint` to print to stderr. See [Print statements](reference-dsl-output-statements.md#print-statements); see also [Dump statements](reference-dsl-output-statements.md#dump-statements) and [Emit statements](reference-dsl-output-statements.md#emit-statements). diff --git a/docs/src/reference-dsl-errors.md.in b/docs/src/reference-dsl-errors.md.in index d50b4ed1ae..5731d956ec 100644 --- a/docs/src/reference-dsl-errors.md.in +++ b/docs/src/reference-dsl-errors.md.in @@ -1,5 +1,29 @@ # DSL errors and transparency +# Handling for data errors + +By default, Miller doesn't stop data processing for a single cell error. For example: + +GENMD-RUN-COMMAND +mlr --csv --from data-error.csv cat +GENMD-EOF + +GENMD-RUN-COMMAND +mlr --csv --from data-error.csv put '$y = log10($x)' +GENMD-EOF + +If you do want to stop processing, though, you have three options. The first is the `mlr -x` flag: + +GENMD-RUN-COMMAND-TOLERATING-ERROR +mlr -x --csv --from data-error.csv put '$y = log10($x)' +GENMD-EOF + +The second is to put `-x` into your [`~/.mlrrc` file](customization.md). + +The third is to set the `MLR_FAIL_ON_DATA_ERROR` environment variable, which makes `-x` implicit. + +# Common causes of syntax errors + As soon as you have a [programming language](miller-programming-language.md), you start having the problem *What is my code doing, and why?* This includes getting syntax errors -- which are always annoying -- as well as the even more annoying problem of a program which parses without syntax error but doesn't do what you expect. The syntax-error message gives you line/column position for the syntax that couldn't be parsed. The cause may be clear from that information, or perhaps not. Here are some common causes of syntax errors: @@ -10,7 +34,7 @@ The syntax-error message gives you line/column position for the syntax that coul * Curly braces are required for the bodies of `if`/`while`/`for` blocks, even when the body is a single statement. -As for transparency: +# Transparency * As in any language, you can do `print`, or `eprint` to print to stderr. See [Print statements](reference-dsl-output-statements.md#print-statements); see also [Dump statements](reference-dsl-output-statements.md#dump-statements) and [Emit statements](reference-dsl-output-statements.md#emit-statements). diff --git a/docs/src/reference-main-flag-list.md b/docs/src/reference-main-flag-list.md index 8e2daf9d02..0a93e12e2d 100644 --- a/docs/src/reference-main-flag-list.md +++ b/docs/src/reference-main-flag-list.md @@ -289,6 +289,7 @@ These are flags which don't fit into any other category. * `-I`: Process files in-place. For each file name on the command line, output is written to a temp file in the same directory, which is then renamed over the original. Each file is processed in isolation: if the output format is CSV, CSV headers will be present in each output file, statistics are only over each file's own records; and so on. * `-n`: Process no input files, nor standard input either. Useful for `mlr put` with `begin`/`end` statements only. (Same as `--from /dev/null`.) Also useful in `mlr -n put -v '...'` for analyzing abstract syntax trees (if that's your thing). * `-s {file name}`: Take command-line flags from file name. For more information please see https://miller.readthedocs.io/en/latest/scripting/. +* `-x`: If any record has an error value in it, report it and stop the process. The default is to print the field value as `(error)` and continue. ## Output-colorization flags diff --git a/xtodo.txt b/xtodo.txt index ff25ea45e4..e3dab2ea53 100644 --- a/xtodo.txt +++ b/xtodo.txt @@ -1,7 +1,5 @@ ---------------------------------------------------------------- -* optional env var: MLR_DATA_ERROR_FAIL_FAST or somesuch * look at: mr -vvv test/cases/io-spec-tsv/0004/cmd -* doc page w/ options incl .mlrrc ---------------------------------------------------------------- From f1d1674f739cda33e33feef76a3b0ee6d41eabbe Mon Sep 17 00:00:00 2001 From: John Kerl Date: Wed, 30 Aug 2023 19:02:38 -0400 Subject: [PATCH 20/22] namefix --- test/cases/io-spec-tsv/0004/cmd | 2 +- test/cases/io-spec-tsv/0004/experr | 2 +- ...ngle-column-with-blank.json => single-column-with-blank.tsv} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename test/cases/io-spec-tsv/0004/{single-column-with-blank.json => single-column-with-blank.tsv} (100%) diff --git a/test/cases/io-spec-tsv/0004/cmd b/test/cases/io-spec-tsv/0004/cmd index 735d4f3dfb..a49dff7b0a 100644 --- a/test/cases/io-spec-tsv/0004/cmd +++ b/test/cases/io-spec-tsv/0004/cmd @@ -1 +1 @@ -mlr --itsv --ojson cat ${CASEDIR}/single-column-with-blank.json +mlr --itsv --ojson cat ${CASEDIR}/single-column-with-blank.tsv diff --git a/test/cases/io-spec-tsv/0004/experr b/test/cases/io-spec-tsv/0004/experr index 750e0a5781..77ead78b2d 100644 --- a/test/cases/io-spec-tsv/0004/experr +++ b/test/cases/io-spec-tsv/0004/experr @@ -1,2 +1,2 @@ -mlr: mlr: TSV header/data length mismatch 1 != 0 at filename test/cases/io-spec-tsv/0004/single-column-with-blank.json line 4. +mlr: mlr: TSV header/data length mismatch 1 != 0 at filename test/cases/io-spec-tsv/0004/single-column-with-blank.tsv line 4. . diff --git a/test/cases/io-spec-tsv/0004/single-column-with-blank.json b/test/cases/io-spec-tsv/0004/single-column-with-blank.tsv similarity index 100% rename from test/cases/io-spec-tsv/0004/single-column-with-blank.json rename to test/cases/io-spec-tsv/0004/single-column-with-blank.tsv From 026889e5d4da8a7de417746e0aec4befac5588be Mon Sep 17 00:00:00 2001 From: John Kerl Date: Wed, 30 Aug 2023 19:22:16 -0400 Subject: [PATCH 21/22] fix broken test --- test/cases/dsl-gmt-date-time-functions/0002/expout | 6 +++--- test/cases/dsl-gmt-date-time-functions/0003/expout | 6 +++--- test/cases/dsl-gmt-date-time-functions/0004/expout | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/cases/dsl-gmt-date-time-functions/0002/expout b/test/cases/dsl-gmt-date-time-functions/0002/expout index 62c36ca091..f50b94f329 100644 --- a/test/cases/dsl-gmt-date-time-functions/0002/expout +++ b/test/cases/dsl-gmt-date-time-functions/0002/expout @@ -21,6 +21,6 @@ n,sec,gmt 20,2000000000.99900007,2033-05-18T03:33:20.9Z 21,2000000000.99999905,2033-05-18T03:33:20.9Z 22,2000000001.00000000,2033-05-18T03:33:21.0Z -23,, -24,x,x -25,123x,123x +23,,(error) +24,x,(error) +25,123x,(error) diff --git a/test/cases/dsl-gmt-date-time-functions/0003/expout b/test/cases/dsl-gmt-date-time-functions/0003/expout index 54b93e2c86..cd68f6448a 100644 --- a/test/cases/dsl-gmt-date-time-functions/0003/expout +++ b/test/cases/dsl-gmt-date-time-functions/0003/expout @@ -21,6 +21,6 @@ n,sec,gmt 20,2000000000.99900007,2033-05-18T03:33:20.999Z 21,2000000000.99999905,2033-05-18T03:33:20.999Z 22,2000000001.00000000,2033-05-18T03:33:21.000Z -23,, -24,x,x -25,123x,123x +23,,(error) +24,x,(error) +25,123x,(error) diff --git a/test/cases/dsl-gmt-date-time-functions/0004/expout b/test/cases/dsl-gmt-date-time-functions/0004/expout index b48a06fe64..462f7f4c8d 100644 --- a/test/cases/dsl-gmt-date-time-functions/0004/expout +++ b/test/cases/dsl-gmt-date-time-functions/0004/expout @@ -21,6 +21,6 @@ n,sec,gmt 20,2000000000.99900007,2033-05-18T03:33:20.999000Z 21,2000000000.99999905,2033-05-18T03:33:20.999999Z 22,2000000001.00000000,2033-05-18T03:33:21.000000Z -23,, -24,x,x -25,123x,123x +23,,(error) +24,x,(error) +25,123x,(error) From 4e46d346c67b1a38e7afe4408eb9b9775199c1f8 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Wed, 30 Aug 2023 19:26:23 -0400 Subject: [PATCH 22/22] make dev --- docs/src/manpage.md | 3 +++ docs/src/manpage.txt | 3 +++ docs/src/reference-dsl-errors.md | 4 +--- internal/pkg/mlrval/mlrval_sort_test.go | 8 ++++---- man/manpage.txt | 3 +++ man/mlr.1 | 3 +++ 6 files changed, 17 insertions(+), 7 deletions(-) diff --git a/docs/src/manpage.md b/docs/src/manpage.md index a19f46f142..c4a7b38562 100644 --- a/docs/src/manpage.md +++ b/docs/src/manpage.md @@ -603,6 +603,9 @@ MILLER(1) MILLER(1) -s {file name} Take command-line flags from file name. For more information please see https://miller.readthedocs.io/en/latest/scripting/. + -x If any record has an error value in it, report it and + stop the process. The default is to print the field + value as `(error)` and continue. 1mOUTPUT-COLORIZATION FLAGS0m Miller uses colors to highlight outputs. You can specify color preferences. diff --git a/docs/src/manpage.txt b/docs/src/manpage.txt index a91bfe4a2d..de6ca2f576 100644 --- a/docs/src/manpage.txt +++ b/docs/src/manpage.txt @@ -582,6 +582,9 @@ MILLER(1) MILLER(1) -s {file name} Take command-line flags from file name. For more information please see https://miller.readthedocs.io/en/latest/scripting/. + -x If any record has an error value in it, report it and + stop the process. The default is to print the field + value as `(error)` and continue. 1mOUTPUT-COLORIZATION FLAGS0m Miller uses colors to highlight outputs. You can specify color preferences. diff --git a/docs/src/reference-dsl-errors.md b/docs/src/reference-dsl-errors.md index 7755284c56..fa9a74636d 100644 --- a/docs/src/reference-dsl-errors.md +++ b/docs/src/reference-dsl-errors.md @@ -59,7 +59,7 @@ mlr: field y: log10: unacceptable type string with value "text" mlr: exiting due to data error. -The second is to put `-x` into your [`~/.mlrrc file`](customization.md). +The second is to put `-x` into your [`~/.mlrrc` file](customization.md). The third is to set the `MLR_FAIL_ON_DATA_ERROR` environment variable, which makes `-x` implicit. @@ -77,8 +77,6 @@ The syntax-error message gives you line/column position for the syntax that coul # Transparency -As for transparency: - * As in any language, you can do `print`, or `eprint` to print to stderr. See [Print statements](reference-dsl-output-statements.md#print-statements); see also [Dump statements](reference-dsl-output-statements.md#dump-statements) and [Emit statements](reference-dsl-output-statements.md#emit-statements). * The `-v` option to `mlr put` and `mlr filter` prints abstract syntax trees for your code. While not all details here will be of interest to everyone, certainly this makes questions such as operator precedence completely unambiguous. diff --git a/internal/pkg/mlrval/mlrval_sort_test.go b/internal/pkg/mlrval/mlrval_sort_test.go index 7af350c7e6..9e1f45ac81 100644 --- a/internal/pkg/mlrval/mlrval_sort_test.go +++ b/internal/pkg/mlrval/mlrval_sort_test.go @@ -54,11 +54,11 @@ func TestComparators(t *testing.T) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Across-type lexical comparisons - assert.Equal(t, -1, LexicalAscendingComparator(i10, btrue)) // "10" < "true" - assert.Equal(t, -1, LexicalAscendingComparator(i10, sabc)) // "10" < "abc" - assert.Equal(t, 1, LexicalAscendingComparator(i10, FromErrorString("foo"))) // "10" > "(error)" + assert.Equal(t, -1, LexicalAscendingComparator(i10, btrue)) // "10" < "true" + assert.Equal(t, -1, LexicalAscendingComparator(i10, sabc)) // "10" < "abc" + assert.Equal(t, 1, LexicalAscendingComparator(i10, FromErrorString("foo"))) // "10" > "(error)" - assert.Equal(t, 1, LexicalAscendingComparator(bfalse, sabc)) // "false" > "abc" + assert.Equal(t, 1, LexicalAscendingComparator(bfalse, sabc)) // "false" > "abc" assert.Equal(t, 1, LexicalAscendingComparator(bfalse, FromErrorString("foo"))) // "false" > "(error)" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/man/manpage.txt b/man/manpage.txt index a91bfe4a2d..de6ca2f576 100644 --- a/man/manpage.txt +++ b/man/manpage.txt @@ -582,6 +582,9 @@ MILLER(1) MILLER(1) -s {file name} Take command-line flags from file name. For more information please see https://miller.readthedocs.io/en/latest/scripting/. + -x If any record has an error value in it, report it and + stop the process. The default is to print the field + value as `(error)` and continue. 1mOUTPUT-COLORIZATION FLAGS0m Miller uses colors to highlight outputs. You can specify color preferences. diff --git a/man/mlr.1 b/man/mlr.1 index 95cbcaf7c4..bda00b93a3 100644 --- a/man/mlr.1 +++ b/man/mlr.1 @@ -701,6 +701,9 @@ These are flags which don't fit into any other category. -s {file name} Take command-line flags from file name. For more information please see https://miller.readthedocs.io/en/latest/scripting/. +-x If any record has an error value in it, report it and + stop the process. The default is to print the field + value as `(error)` and continue. .fi .if n \{\ .RE