From ed6cf767d0c046c22b5b28381b5dd9d22599b5c2 Mon Sep 17 00:00:00 2001 From: chakr Date: Fri, 23 Dec 2022 10:25:05 -0500 Subject: [PATCH] fix listen, dump; add over, rot, depth, aoc 2022 --- LICENSE | 0 SPEC.html | 423 ++++++ SPEC.md | 45 + build.sh | 38 +- buildall.sh | 37 + examples/aoc2022/day1/input.txt | 2244 +++++++++++++++++++++++++++++++ examples/aoc2022/day1/p1.vq | 18 + examples/aoc2022/day1/p1.vqe | 18 + examples/aoc2022/day1/p2.vqe | 18 + examples/list.vqe | 1 + examples/test.vqe | 2 - varaq/interpreter.go | 41 +- varaq/scanner.go | 11 +- varaq/token.go | 6 + 14 files changed, 2854 insertions(+), 48 deletions(-) mode change 100644 => 100755 LICENSE create mode 100755 SPEC.html create mode 100755 buildall.sh create mode 100755 examples/aoc2022/day1/input.txt create mode 100755 examples/aoc2022/day1/p1.vq create mode 100755 examples/aoc2022/day1/p1.vqe create mode 100755 examples/aoc2022/day1/p2.vqe create mode 100755 examples/list.vqe diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/SPEC.html b/SPEC.html new file mode 100755 index 0000000..2631c84 --- /dev/null +++ b/SPEC.html @@ -0,0 +1,423 @@ + + + + + 1 Language Overview + + + + + + + + + +

var'aq Specification

+

For better flavor text please read the Original var'aq spec the following is a trimmed down version of the spec with a couple of fixes and addendums to how this implementation of the language works.

+

1 Language Overview

+

var'aq is a stack-based, RPN programming language with points of similarity to Lisp, Forth, and PostScript. It is more of a functional language than an imperative (Algol-like) language; most operations are dependent on the stack and bypass the local variable store altogether.

+

1.2 Filetypes

+ +

2 Language Basics

+

This section describes the fundamental var'aq language constructs and data types.

+

2.1 Stack Operations

+

These operations directly manipulate the var'aq operand stack. The operand stack can hold any of four kinds of data: numbers (real or integer), strings, functions, or arrays. It is best described as "translucent", similar to the transparent stack of Forth or PostScript but somewhat more restricted. The internal data representation of the stack is not available to the programmer.

+

2.1.1 pop/woD

+

obj woD -

+

Pops and discards the top item on the stack. The literal meaning is discard.

+

Errors: stackUnderflow

+

2.1.2 dup/latlh

+

obj latlh obj obj

+

Duplicates the top object on the stack.

+

Errors: stackUnderflow

+

2.1.3 exch/tam

+

obj1 obj2 tam obj2 obj1

+

Inverts the order of the top two objects on the stack.

+

Errors: stackUnderflow

+

2.1.4 clear/chImmoH

+

... obj chIm -

+

Empties the stack.

+

Errors: none

+

2.1.5 remember/qaw

+

- qaw flag

+

Puts a flag (like PostScript's mark) on the stack. The internal representation of the flag is not available to the programmer.

+

Errors: none

+

2.1.6 forget/qawHa'

+

... flag ... qawHa' ...

+

Clears the stack down to the flag and pops the flag. If there is no flag present, the stack is emptied completely.

+

Errors: none

+

2.1.7 dump/Hotlh (lit. scan)

+

... Hotlh ...

+

Prints the contents of the operand stack to STDOUT without changing them. Note: the Hotlh operator is a debugging operator and is not intended for use in programs; it is merely documented here because it might be useful to a var'aq developer. In particular, the output format of this operator is implementation-defined and will not be specified in this document. Hotlh may be redefined to take such arguments as the implementor feels appropriate.

+

Errors: implementation-defined.

+

2.1.8 disinter

+

Returns the value just above the top mark on the stack without disturbing the stack above it.

+

2.2 Data/Code Operations

+

var'aq, like many similar languages, does not distinguish between code and data. These operations include operators to associate names with objects and executable procedures, as well as operators to define and manage data structures. Note that variables and procedures live in a common namespace, since the act of pushing the content of a variable is essentially the same as executing the variable's name.

+

2.2.1 ~ (quote/lI'moH)

+

- ~ obj obj

+

The ~ operator is a special form, as it is not a postfix operator. When the interpreter encounters a ~, it pushes the next token on the stack as is regardless of whether it is a defined name. (Attempting to push an undefined name without a ~ will generate an undefinedName error.)

+

The literal meaning of this operator's name is "make useful". Errors: none

+

2.2.2 {

+

Begins the creation of an anonymous procedure. The process is implementation-dependent.

+

2.2.3 }

+

- } proc

+

Completes procedure construction and pushes a reference to the completed procedure on the stack. Does not execute the procedure.

+

Errors: noDefinedProc

+

2.2.4 name/pong

+

obj id pong -

+

Associates obj with id and places it in the system lookup space. Conventionally used to associate new operator names with procedure objects.

+

Example: ~ add3 { boq boq cha' } pong

+

Pushes the name add3 and a procedure object on the stack, then binds the name to the procedure.

+

Errors: stackUnderflow, noDefinedProc

+

2.2.5 set/cher

+

obj id cher -

+

Reassigns the value of a value already in the system lookup space. Used primarily for variable assignments.

+

Errors: stackUnderflow, noSuchName

+

2.2.6 (* ... *) (comment)

+

Marks a comment in a program. All such comments are treated as single tokens and ignored.

+

2.2.7 //name

+

Causes the interpreter to import a file with the name name.vq(e) and execute it as if it is part of the currently executing program. Essentially equivalent to #include in C.

+

An example can be found at the top of the test.vqe example.

+

Note: you must use either absolute paths or paths relitive to the location of the interpeter

+

2.3 Control Flow

+

var'aq supports a small but sufficient supply of conditional and iterative operators.

+

2.3.1 ifyes/HIja'chugh

+

bool proc HIja'chugh -

+

Pops the proc object off the stack, then evaluates the boolean. If it's true, the proc object is evaluated; otherwise, it's thrown out.

+

Errors: stackUnderflow, noDefinedProc

+

2.3.2 ifno/ghobe'chugh

+

bool proc ghobe'chugh -

+

Similar to HIja'chugh above, but executes proc only if bool is false.

+

Errors: stackUnderFlow, noDefinedProc

+

2.3.3 choose/wIv

+

bool wIv bool bool

+

Duplicates a boolean value on top of the stack. Allows paired HI'ja'chugh/ghobe'chugh clauses.

+

Note: To the untrained eye, it may seem as though wIv and latlh are identical. This is true in the reference implementation, but may not be in any version that actually does some level of type checking. This bit of syntactic sugar should never be relied upon; always use wIv in this situation.

+

2.3.4 eval/chov

+

proc chov -

+

Pops a proc object off the stack and executes it.

+

Errors: stackUnderflow, noDefinedProc

+

2.3.5 escape/nargh

+

bool nargh -

+

Exit the current procedure. Useful for exit conditions on loops. Will terminate the current session if used top-level.

+

2.3.6 repeat/vangqa'

+

val proc vangqa' -

+

Pops val and proc off the stack and executes proc val times.

+

2.4 List Operations

+

var'aq supports a series of operators for management of lists (ghomHom, which seems to mean something like "cluster"). These primitives are the language's primary way of managing aggregate objects and work much like similar operators in LISP; a more sophisticated paradigm, such as OO extensions or the like, can be built with these operators.

+

Note that "objects" as they stand in var'aq are largely singletons as in JavaScript; there is no inherent concept of object-orientation or anything like it in standard var'aq.

+

2.4.1 (

+

Begins a list definition.

+

2.4.2 )

+

( item1 item2 ... ) list

+

Creates a list and pushes it onto the stack.

+

2.4.3 split/SIj

+

list SIj item1 list

+

Pops a list off the stack and returns the first item and the rest of the list.

+

2.4.4 cons/muv

+

list item1 ... muv list

+

Takes an object and adds it to the head of a list. Equivalent to the LISP cons operator.

+

2.4.5 shatter/ghorqu'

+

list ghorqu' item1 item2 ...

+

Reduces a list to its component elements and pushes them on the stack in order.

+

Note: The precise meaning of the construction ghorqu' is a bit obscure; the rendering shatter is idiomatic and may derive from a nonstandard dialect. Standard Klingon would generally prefer jor, meaning explode.)

+

2.4.6 empty?/chIm'a'

+

list chIm'a' bool

+

Examines a list on the stack and returns 1 if its value is null (pagh), a 0 if it contains anything.

+

2.4.7 consume

+

obj1 obj2 ... mark consume list

+

Pops all objects on the stack down to mark and returns them in a list.

+

Note: some implementations also have an operator known as bite/chop, equivalent to the Lisp cdr. This is not required in any standard var'aq implementation and can easily be rendered by the function

+
~ chop { SIj woD } pong
+
+

2.5 String Operators

+

tlheghjangwI'mey

+

2.5.1 strtie/tlheghrar

+

str1 str2 tlheghrar str3

+

Concatenates the top two strings on the stack into one.

+

2.5.2 compose/naQmoH

+

mark str1 str2 ... strn naQmoH strn'

+

Pops objects (executing proc objects if necessary) off the stack until a marker (placed by qaw) is hit and combines them into one string.

+

2.5.3 streq?/tlheghrap'a'

+

str1 str2 tlheghrap'a' bool

+

Pops the top two strings on the stack, compares them, and returns 1 if identical, 0 if not.

+

2.5.4 strcut/tlheghpe'

+

str startval endval tlheghpe' substr

+

Pops two values and a string and returns the section of the string between character startval and character endval.

+

2.5.5 strmeasure/tlheghjuv

+

str tlheghjuv val

+

Pops a string off the stack and returns its length in characters.

+

2.5.6 explode/jor

+

str jor list

+

Separates individual "words" in a string by whitespace.

+

3 Mathematical Operators

+

mI'jangwI'mey

+

3.1 Arithmetic Operations

+

toghwI'mey

+

Arithmetic operators usually work with real numbers unless otherwise stated. The number operators (sec 3.3) can convert them to integers if necessary.

+

3.1.1 add/boq

+

a b boq sum

+

Pops the top two values on the stack and replaces them with their sum.

+

3.1.2 sub/boqHa'

+

a b boqHa' difference

+

Pops the top two values on the stack and replaces them with a - b.

+

3.1.3 mul/boq'egh

+

a b boq'egh product

+

Pops the top two values on the stack and replaces them with their product.

+

3.1.4 div/boqHa''egh

+

a b wav quotient

+

Pops the top two values on the stack and replaces them with a/b.

+

3.1.5 idiv/HabboqHa''egh (lit. full-divide)

+

a b HabboqHa''egh quotient

+

Pops the top two values on the stack and replaces them with the results of an integer division operation.

+

3.1.6 mod/chuv (lit. leftover)

+

a b chuv remainder

+

Pops the top two values and returns the remainder of a mod b.

+

3.1.7 pow/boqHa'qa' (lit. remultiply)

+

base exp boqHa'qa' real

+

Pops the top two values and returns base^exp.

+

3.1.8 sqrt/loS'ar (lit. fourth-howmuch)

+

angle loS'ar real

+

Returns the square root of val.

+

3.1.9 add1/wa'boq

+

a wa'boq a+1

+

Increments the top value on the stack by one.

+

3.1.10 sub1/wa'boqHa'

+

a wa'boqHa' a-1

+

Decrements the top value on the stack by one.

+

3.2 Trigonometric and Logarithmic Operators

+

SIHpojjangwI'mey 'ej ghurjangwI'mey

+

3.2.1 sin/yu'egh (lit. wave)

+

angle yu'egh real

+

Returns the sine of val.

+

3.2.2 cos/yu'eghHa' (lit. counter-wave)

+

angle yu'eghHa' cos(val)

+

Returns the cosine of val.

+

3.2.3 tan/qojmI' (lit. cliffnumber)

+

angle qojmI' tan(val)

+

Returns the tangent of val.

+

3.2.4 atan/qojHa' (lit. anticliff)

+

num den qojHa' angle

+

Returns the arctangent of num / den.

+

3.2.5 ln/ghurtaH

+

num ghurtaH real

+

Returns the natural log of num.

+

3.2.6 log/maHghurtaH

+

num maHghurtaH real

+

Returns the base 10 log of num.

+

3.2.7 log3/wejghurtaH

+

num wejghurtaH real

+

Returns the base 3 log of num.

+

3.3 Numerical Operators and Constants

+

This section describes operators that operate on numbers themselves, as well as common system-level constants.

+

3.3.1 clip/poD

+

real poD int

+

Removes the fractional portion of a real number (equivalent to floor(real).

+

3.3.2 smooth/Hab (lit. smooth)

+

real Hab int

+

Rounds a number to the nearest integer.

+

3.3.3 howmuch/'ar

+

num 'ar num2

+

Returns the absolute value of num.

+

3.3.4 setrand/mIScher

+

num mIScher -

+

Sets the random number generator seed value to num. Not common, since most var'aq implementations have a rather arcane formula for picking a pseudo-random seed value.

+

3.3.5 rand/mIS

+

num mIS real

+

Returns a random real number in the range 0 to num. If there is no meaningful input on the stack,

+

3.3.6 pi/HeHmI'

+

Pushes the value pi (~3.14159...) onto the stack. The Klingon name literally means "edge-number".

+

3.3.7 e/ghurmI'

+

Pushes the value e onto the stack. The Klingon name literally means "growth-number".

+

3.3.8 int?/HabmI''a'

+

val HabmI''a' bool Pops the top value on the stack and returns 1 if it is an integer, 0 if not.

+

3.3.9 number?/mI''a'

+

val mI''a' bool

+

Pops the top value off the stack and returns 1 if it's a number, 0 if it's something else.

+

3.3.10 numberize/mI'moH

+

str mi'moH val

+

Pops a string off the stack, converts it into a numerical value, and returns it.

+

3.4 Bitwise operators

+

Though var'aq makes no clear distinction between integers and reals, it is nevertheless useful to be able to manipulate a number on the bit level. The following operators assume that their operands will always be treated as integers; effects on floating-point values are undefined, and may be disallowed at the implementor's discretion.

+

3.4.1 isolate/mobmoH

+

a b mobmoH result

+

Performs a bitwise AND on a and b.

+

3.4.2 mix/DuD

+

a b DuD result

+

Performs a bitwise OR on a and b.

+

3.4.3 contradict/tlhoch

+

a b tlhoch result

+

Performs a bitwise XOR on a and b.

+

3.4.4 compl/Qo'moH

+

val Qo'moH ~val

+

Returns the one's-complement of val. Note: The literal meaning is something like "make it say no".

+

3.4.5 shiftright/nIHghoS

+

a b nIHghoS result

+

Shifts a right b places, preserving the sign of the value.

+

3.4.6 shiftleft/poSghoS

+

a b poSghoS result

+

Shifts a left b places.

+

4 Relational and Logical Operators

+

4.1 Relational Operators and Predicate Functions

+

yu'jangwI'mey

+

4.1.1 gt?/law''a'

+

a b law''a' bool

+

Pops a and b off the stack, compares them, and returns a boolean value of true if a is larger.

+

4.1.2 lt?/puS'a'

+

a b puS'a' bool

+

Pops a and b off the stack, compares them, and returns a boolean value of true if a is smaller.

+

4.1.3 eq?/rap'a'

+

a b rap'a' bool

+

Pops a and b off the stack, compares them, and returns a boolean value of true if a is the same as b.

+

4.1.4 ge?/law'rap'a'

+

a b law'rap'a' bool

+

Pops a and b off the stack, compares them, and returns a boolean value of true if a is greater than or equal to b.

+

4.1.5 le?/puSrap'a'

+

a b puSrap'a' bool

+

Pops a and b off the stack, compares them, and returns a boolean value of true if a is less than or equal to b.

+

4.1.6 ne?/rapbe'a'

+

a b rapbe'a' bool

+

Pops a and b off the stack, compares them, and returns a boolean value of true if a is not equal to b.

+

4.1.7 null?/pagh'a'

+

obj pagh'a' bool

+

Examines the top object on the stack and returns a 1 if null, a 0 if not.

+

4.1.8 negative?/taH'a'

+

val taH'a' bool

+

Pops the top number on the stack and returns a 1 if less than 0, a 0 if not.

+

4.2 Logical Operators

+

vItjangwI'mey

+

Note that these are strictly logical operators, not bitwise.

+

4.2.1 and/je

+

a b je bool

+

Evaluates b and a and returns a 1 if both are true, a 0 if not.

+

4.2.2 or/joq

+

a b joq bool

+

Evaluates b and a and returns a 1 if one or both are true, a 0 if both are false.

+

4.2.3 xor/ghap

+

a b ghap bool

+

Evaluates b and a and returns a 1 if only one is true, a 0 otherwise.

+

4.2.4 not/ghobe'

+

val ghobe' bool

+

Evaluates val and returns 1 if true, 0 if not.

+

5 Input/Output and File Operators

+

The var'aq Level 0 specification essentially handles console I/O and files in a manner very similar to the UNIX model.

+

5.1 Console I/O

+

The console I/O model at this point is very simple: write, read, error.

+

5.1.1 disp/cha'

+

obj cha' -

+

Pops the top object on the stack and writes it to STDOUT. Note that certain types of objects will generate meaningless output, particularly anonymous proc objects.

+

5.1.2 listen/'Ij

+

- 'Ij str

+

Reads one line of input and stores it as a string on top of the stack.

+

5.1.3 complain/bep

+

str bep -

+

Pops str and prints it to stderr.

+

6 System Variables

+

patSarwI'mey

+

This section describes var'aq keywords that do no more than put set values on the stack. Many of them are not precisely constants but more like environment variables.

+ +

6.1.1 newline/chu'DonwI'

+

- chu'DonwI' '\n'

+

Prints a carriage return.

+

6.1.2 tab/chu'tut

+

- chu'DonwI' '\t'

+

Advances by one tab stop.

+

6.2 Environment Constants

+

6.2.1 whereami/nuqDaq_jIH

+

- nuqDaq_jIH "string of your local ip address"

+

Returns the IP address of the machine the interpreter is running on.

+

6.2.2 version/pongmI'

+

- pongmI' "string of version"

+

Returns the current interpreter version number. The reference interpreter returns a date stamp.

+

6.2.3 argv/taghDe'

+

- taghDe' (arg1, arg2, ...)

+

Pushes the command line arguments on the stack as a list.

+

7 New Operators

+

The following are all new operators that are not included in the original perl implementation of var'aq

+

7.1 Stack Operations

+

These are stolen directly from Forth (specifically the FORTH-79 Handy Reference from the book Forth for the Complete Idiot),

+

They are very useful for doing operations without clobbering the stack

+

7.1.1 over/QI

+

obj1 obj2 QI obj1 obj2 obj1

+

Make a copy of the second item on top of the stack.

+

The direct Klingon translation for QI is bridge, as in a bridge over a river, which works close enough.

+

Errors: stackUnderflow

+

7.1.2 rot/jIr

+

obj1 obj2 obj3 jIr obj2 obj3 obj1

+

Rotate the third item to the top of the stack.

+

Errors: stackUnderflow

+

7.1.3 depth/juv

+

- juv num

+

Count the number of items on the stack and push that number to the top of the stack.

+

Errors: stackUnderflow

+ + + + + \ No newline at end of file diff --git a/SPEC.md b/SPEC.md index a1ebe36..74d3805 100755 --- a/SPEC.md +++ b/SPEC.md @@ -606,23 +606,68 @@ This section describes _var'aq_ keywords that do no more than put set values on #### 6.1.1 newline/chu'DonwI' +_- `chu'DonwI'` '\n'_ + Prints a carriage return. #### 6.1.2 tab/chu'tut +_- `chu'DonwI'` '\t'_ + Advances by one tab stop. #### 6.2 Environment Constants #### 6.2.1 whereami/nuqDaq\_jIH +_- `nuqDaq_jIH` "string of your local ip address"_ + Returns the IP address of the machine the interpreter is running on. #### 6.2.2 version/pongmI' +_- `pongmI'` "string of version"_ + Returns the current interpreter version number. The reference interpreter returns a date stamp. #### 6.2.3 argv/taghDe' +_- `taghDe'` (arg1, arg2, ...)_ + Pushes the command line arguments on the stack as a list. +## 7 New Operators + +The following are all new operators that are not included in the original perl implementation of _var'aq_ + +### 7.1 Stack Operations + +These are stolen directly from _Forth_ (specifically the [_FORTH-79 Handy Reference_](http://www.forth.org/Ting/Forth-for-the-Complete-Idiot/Forth-79-Handy-Reference.pdf) from the book _Forth for the Complete Idiot_), + +They are very useful for doing operations without clobbering the stack + +#### 7.1.1 over/QI + +_obj1 obj2 `QI` obj1 obj2 obj1_ + +Make a copy of the second item on top of the stack. + +The direct Klingon translation for `QI` is bridge, as in a bridge over a river, which works close enough. + +Errors: stackUnderflow + +#### 7.1.2 rot/jIr + +_obj1 obj2 obj3 `jIr` obj2 obj3 obj1_ + +Rotate the third item to the top of the stack. + +Errors: stackUnderflow + +#### 7.1.3 depth/juv + +_- `juv` num_ + +Count the number of items on the stack and push that number to the top of the stack. + +Errors: stackUnderflow diff --git a/build.sh b/build.sh index 6f32444..19704f3 100755 --- a/build.sh +++ b/build.sh @@ -1,37 +1 @@ -GOOS=plan9 GOARCH=386 go build -o bin/varaq-plan9-386 main.go -GOOS=plan9 GOARCH=amd64 go build -o bin/varaq-plan9-amd64 main.go -GOOS=plan9 GOARCH=arm go build -o bin/varaq-plan9-arm main.go -GOOS=aix GOARCH=ppc64 go build -o bin/varaq-aix-ppc64 main.go -GOOS=darwin GOARCH=amd64 go build -o bin/varaq-darwin-amd64 main.go -GOOS=darwin GOARCH=arm64 go build -o bin/varaq-darwin-arm64 main.go -GOOS=dragonfly GOARCH=amd64 go build -o bin/varaq-dragonfly-amd64 main.go -GOOS=freebsd GOARCH=386 go build -o bin/varaq-freebsd-386 main.go -GOOS=freebsd GOARCH=amd64 go build -o bin/varaq-freebsd-amd64 main.go -GOOS=freebsd GOARCH=arm go build -o bin/varaq-freebsd-arm main.go -GOOS=illumos GOARCH=amd64 go build -o bin/varaq-illumos-amd64 main.go -GOOS=js GOARCH=wasm go build -o bin/varaq.wasm main.go -GOOS=linux GOARCH=386 go build -o bin/varaq-linux-386 main.go -GOOS=linux GOARCH=amd64 go build -o bin/varaq-linux-amd64 main.go -GOOS=linux GOARCH=arm go build -o bin/varaq-linux-arm main.go -GOOS=linux GOARCH=arm64 go build -o bin/varaq-linux-arm64 main.go -GOOS=linux GOARCH=loong64 go build -o bin/varaq-linux-loong64 main.go -GOOS=linux GOARCH=mips go build -o bin/varaq-linux-mips main.go -GOOS=linux GOARCH=mipsle go build -o bin/varaq-linux-mipsle main.go -GOOS=linux GOARCH=mips64 go build -o bin/varaq-linux-mips64 main.go -GOOS=linux GOARCH=mips64le go build -o bin/varaq-linux-mips64le main.go -GOOS=linux GOARCH=ppc64 go build -o bin/varaq-linux-ppc64 main.go -GOOS=linux GOARCH=ppc64le go build -o bin/varaq-linux-ppc64le main.go -GOOS=linux GOARCH=riscv64 go build -o bin/varaq-linux-riscv64 main.go -GOOS=linux GOARCH=s390x go build -o bin/varaq-linux-s390x main.go -GOOS=netbsd GOARCH=386 go build -o bin/varaq-netbsd-386 main.go -GOOS=netbsd GOARCH=amd64 go build -o bin/varaq-netbsd-amd64 main.go -GOOS=netbsd GOARCH=arm go build -o bin/varaq-netbsd-arm main.go -GOOS=openbsd GOARCH=386 go build -o bin/varaq-openbsd-386 main.go -GOOS=openbsd GOARCH=amd64 go build -o bin/varaq-openbsd-amd64 main.go -GOOS=openbsd GOARCH=arm go build -o bin/varaq-openbsd-arm main.go -GOOS=openbsd GOARCH=arm64 go build -o bin/varaq-openbsd-arm64 main.go -GOOS=solaris GOARCH=amd64 go build -o bin/varaq-solaris-amd64 main.go -GOOS=windows GOARCH=386 go build -o bin/varaq-windows-386 main.go -GOOS=windows GOARCH=amd64 go build -o bin/varaq-windows-amd64 main.go -GOOS=windows GOARCH=arm go build -o bin/varaq-windows-arm main.go -GOOS=windows GOARCH=arm64 go build -o bin/varaq-windows-arm64 main.go +go build -o bin/varaq main.go diff --git a/buildall.sh b/buildall.sh new file mode 100755 index 0000000..6f32444 --- /dev/null +++ b/buildall.sh @@ -0,0 +1,37 @@ +GOOS=plan9 GOARCH=386 go build -o bin/varaq-plan9-386 main.go +GOOS=plan9 GOARCH=amd64 go build -o bin/varaq-plan9-amd64 main.go +GOOS=plan9 GOARCH=arm go build -o bin/varaq-plan9-arm main.go +GOOS=aix GOARCH=ppc64 go build -o bin/varaq-aix-ppc64 main.go +GOOS=darwin GOARCH=amd64 go build -o bin/varaq-darwin-amd64 main.go +GOOS=darwin GOARCH=arm64 go build -o bin/varaq-darwin-arm64 main.go +GOOS=dragonfly GOARCH=amd64 go build -o bin/varaq-dragonfly-amd64 main.go +GOOS=freebsd GOARCH=386 go build -o bin/varaq-freebsd-386 main.go +GOOS=freebsd GOARCH=amd64 go build -o bin/varaq-freebsd-amd64 main.go +GOOS=freebsd GOARCH=arm go build -o bin/varaq-freebsd-arm main.go +GOOS=illumos GOARCH=amd64 go build -o bin/varaq-illumos-amd64 main.go +GOOS=js GOARCH=wasm go build -o bin/varaq.wasm main.go +GOOS=linux GOARCH=386 go build -o bin/varaq-linux-386 main.go +GOOS=linux GOARCH=amd64 go build -o bin/varaq-linux-amd64 main.go +GOOS=linux GOARCH=arm go build -o bin/varaq-linux-arm main.go +GOOS=linux GOARCH=arm64 go build -o bin/varaq-linux-arm64 main.go +GOOS=linux GOARCH=loong64 go build -o bin/varaq-linux-loong64 main.go +GOOS=linux GOARCH=mips go build -o bin/varaq-linux-mips main.go +GOOS=linux GOARCH=mipsle go build -o bin/varaq-linux-mipsle main.go +GOOS=linux GOARCH=mips64 go build -o bin/varaq-linux-mips64 main.go +GOOS=linux GOARCH=mips64le go build -o bin/varaq-linux-mips64le main.go +GOOS=linux GOARCH=ppc64 go build -o bin/varaq-linux-ppc64 main.go +GOOS=linux GOARCH=ppc64le go build -o bin/varaq-linux-ppc64le main.go +GOOS=linux GOARCH=riscv64 go build -o bin/varaq-linux-riscv64 main.go +GOOS=linux GOARCH=s390x go build -o bin/varaq-linux-s390x main.go +GOOS=netbsd GOARCH=386 go build -o bin/varaq-netbsd-386 main.go +GOOS=netbsd GOARCH=amd64 go build -o bin/varaq-netbsd-amd64 main.go +GOOS=netbsd GOARCH=arm go build -o bin/varaq-netbsd-arm main.go +GOOS=openbsd GOARCH=386 go build -o bin/varaq-openbsd-386 main.go +GOOS=openbsd GOARCH=amd64 go build -o bin/varaq-openbsd-amd64 main.go +GOOS=openbsd GOARCH=arm go build -o bin/varaq-openbsd-arm main.go +GOOS=openbsd GOARCH=arm64 go build -o bin/varaq-openbsd-arm64 main.go +GOOS=solaris GOARCH=amd64 go build -o bin/varaq-solaris-amd64 main.go +GOOS=windows GOARCH=386 go build -o bin/varaq-windows-386 main.go +GOOS=windows GOARCH=amd64 go build -o bin/varaq-windows-amd64 main.go +GOOS=windows GOARCH=arm go build -o bin/varaq-windows-arm main.go +GOOS=windows GOARCH=arm64 go build -o bin/varaq-windows-arm64 main.go diff --git a/examples/aoc2022/day1/input.txt b/examples/aoc2022/day1/input.txt new file mode 100755 index 0000000..ae1422a --- /dev/null +++ b/examples/aoc2022/day1/input.txt @@ -0,0 +1,2244 @@ +10062 +15651 +1271 +14355 +7220 + +4878 +1754 +8466 +4741 +2582 +3003 +5327 +3172 +1327 +6310 + +22413 +4145 +22294 + +23108 +30453 + +2084 +3496 +4800 +1388 +8728 +6380 +6397 +2558 +2120 +6159 + +25265 +20200 +2083 + +7424 +5830 +2575 +2825 +2234 +6106 +5505 +2847 +2059 +7145 +7223 + +58621 + +2926 +9188 +7432 +1639 +7420 +1161 +5517 +2703 +5446 + +2457 +5814 +1294 +3280 +8531 +8214 +4736 +1964 +1155 +2380 + +2812 +1827 +5533 +1756 +1491 +4127 +6452 +5935 +1415 +6221 +3489 +2681 +4849 +5250 + +2922 +10365 +5819 +10227 +2962 +2702 + +2982 +9254 +14137 +5026 +9374 + +5933 +2888 +2250 +4514 +1825 +5616 +3497 +2988 +1181 +3836 +1032 +5847 +5383 + +5044 +5922 +3155 +1610 +5510 +5016 +6666 +7024 +4649 +2764 +6444 + +12932 + +4764 +4285 +1278 +5020 +5917 +1888 +4757 +6323 +5067 +1314 +1530 +5748 +5573 +5848 + +6078 +6687 +5510 +7642 +6719 +4376 +7733 +1356 +4064 +4159 + +7426 +1147 +4176 +2797 +9484 +7907 +10806 + +24981 +21675 +9324 + +5537 +5730 +1280 +2090 +2963 +5992 +6043 +5141 +3039 +2120 +3664 +3816 +3859 +5406 + +1315 +8662 +2280 +11800 +10201 +3886 + +3048 +4147 +3299 +3912 +1571 +4582 +1621 +2201 +4543 +5377 +3016 +5297 +5213 +1338 +3929 + +5456 +4051 +1621 +5228 +2672 +3277 +4006 +4954 +1487 +5361 +3298 +4335 +3015 +1139 + +2875 +6387 +2926 +5439 +3494 +5287 +3793 +3714 +4944 +1094 +6728 +3302 +6345 + +9641 +5967 +10265 +1129 +3759 +5632 +4913 +6151 + +5890 +4285 +3601 +3344 +7294 +6321 +2730 +6352 +2350 +7214 +4034 +1032 + +4266 +2086 +12754 +8475 +5044 +9616 + +27815 +19415 + +7914 +11106 +6938 +10695 +6902 +2983 +3710 + +7659 +3565 +1310 +11842 + +8750 +17624 +9697 +16020 + +4606 +6296 +2321 +1272 +3504 +7121 +2313 +8016 +7910 +4786 + +11012 +12831 +3980 +12204 + +7996 +7933 +1500 +1810 +4030 +8645 +1710 +7506 +8096 +8661 + +5694 +4145 +3095 +3963 +2396 +5197 +6086 +6793 +5924 +5043 +1241 +5011 + +2410 +7373 +6724 +2641 +1827 +8344 +6833 +8336 +6517 +1376 + +6084 +9909 +1760 +10864 +4904 +6734 +9492 + +8002 +4098 + +17545 +1504 +17040 +14118 + +1103 +5378 +6135 +6207 +3143 +5550 +5723 +5494 +2841 +1461 +2413 +2252 +1904 +3474 + +1788 +5889 +7810 +8520 +5415 +4633 +1422 +9526 +6762 + +1187 +2137 +6551 +8399 +1510 +7099 +3465 +5179 + +7056 +3142 +3237 +4910 +6656 +3680 +2619 +5549 +5737 +4493 +5359 +1336 + +4690 +6692 +4638 +5490 +6449 +1518 +5872 +7935 +7742 +1895 +4528 + +4929 +5947 +5044 +1627 +5037 +6646 +5949 +2142 +2362 +3050 +6390 +5467 +5496 + +11896 +13381 +1055 +3993 +4275 +12480 + +1903 +1527 +3280 +3748 +3315 +1058 +2541 +4245 +4386 +4792 +4937 +2345 +2551 +1901 + +2674 +9184 +3423 +1954 +2788 +5954 +7827 +4466 +4901 + +4653 +12104 +14737 +8740 +4164 + +5317 +5734 +4580 +3244 +5509 +4009 +2576 +4137 +1282 +5506 +3530 +3057 +5408 +5952 +1849 + +9691 +16403 +16828 + +3653 +6762 +2042 +4618 +4212 +6293 +4782 +2071 +6303 +1662 +6814 + +3720 +6801 +2350 +4456 +4623 +3242 +2471 +4104 +4096 +3641 +4022 +3702 +3169 + +7146 +5318 +1820 +3845 +4955 +4134 +8848 +6614 +5497 + +11545 +4050 +20095 + +8230 +11577 +6426 +4671 +11838 + +1726 +7355 +8115 +2780 + +1795 +4697 +10410 +8064 +2370 +9497 +1221 + +2909 +6719 +2733 +4335 +1327 +1672 +1297 +6705 +5209 +6690 +5855 +5432 +3804 + +7874 +7949 +6658 +1621 +8850 +3235 +9142 +2856 + +6968 +7042 + +7463 +8035 +4908 +5032 +4791 +2030 +1768 +8611 +2114 +8748 + +11054 +16021 +9826 +11604 +4819 + +11214 +4850 +11665 +1891 +1347 +4053 +4570 + +66862 + +1597 +6127 +6229 +11518 +9308 +9661 +11410 + +13224 +1160 +1978 +13018 +14604 + +2773 +3885 +2383 +2850 +1758 +5724 +4418 +4637 +1510 +3870 +3793 +4116 +6281 +2026 + +3714 +2840 +2116 +3505 +3941 +6676 +5696 +3216 +6406 +4660 +4974 +2005 +5293 + +2580 +1645 +5677 +5376 +6527 +4410 +6837 +3069 +2399 +3727 +5658 +4817 +5911 + +2126 +2851 +2766 +8660 +8181 +3449 +2765 +1299 + +18470 +9129 +17956 +14494 + +1033 +4468 +5938 +2874 +2406 +1175 +5997 + +1256 +7932 +1544 +2772 +5709 +1348 +2919 + +4399 +1449 +8295 +7470 +2088 +1958 +2857 +1722 +5204 + +8161 +6865 +6428 +4807 +2173 +8614 +5109 +1769 +2125 + +1112 +7417 +1328 +6385 +4670 +2840 +3293 +6438 +6639 +6129 +4144 + +5554 +15529 +1499 + +9459 +3175 +7412 +10610 +10283 +6807 +10056 +8657 + +5195 +1397 +5365 +3713 +4376 +4034 +2480 +2665 +2566 +4664 +5262 +5913 +2455 +6048 +4488 + +10875 + +5322 +8688 +2636 +14243 + +11403 +7465 +10079 +2270 +15254 + +11758 +7630 +5137 +6345 +7119 +10008 +6125 + +5184 + +4306 +1159 +6483 +5131 +5009 +4585 +2996 +3514 +4009 +4788 +6841 +2189 +3030 + +3132 +6730 +5733 +2747 +6464 +5221 +4567 +3528 +4264 +6006 +3295 + +4829 +23038 +16150 + +1519 +10692 +11102 +6321 +2948 +11851 +6301 + +5787 +2664 +6046 +4527 +1955 +5270 +1557 +4567 +5631 +2150 +4612 +3044 +2568 +3589 +5334 + +2303 +10849 +3983 +10010 +4854 +2111 + +4576 +1236 +3111 +4898 +5930 +5241 +2783 +5451 +6549 +5623 +7257 +2589 + +6031 +4307 +6669 +7866 +4333 +2069 +2778 +5463 +7149 +3091 +1001 + +8737 +1843 +4676 +4381 +6164 +2616 +2453 +1739 +4845 +2909 + +1396 +2963 +10672 +11217 +9975 +6511 +8694 + +5262 +3743 +1895 +3811 +6089 +4659 +4195 +4633 +1928 +3865 +2166 +4947 +5040 +4052 +5291 + +16754 +8916 +17259 +17813 + +9683 +13286 +13577 +9343 +1792 +3335 + +25505 +12891 +20104 + +8618 +6560 +4584 +1118 +3931 +1229 +6759 +8275 + +18418 +14090 +3552 +3156 + +4681 +2564 +4557 +4838 +2048 +3097 +4513 +5181 +3803 +1857 +3836 +3089 +4322 +4049 + +3768 +12991 +1680 +2378 + +2609 +5115 +2179 +6126 +1423 +1300 +6113 +3720 +1279 +4681 +1147 +1728 +2087 +4708 + +11919 +12306 +11697 +9806 +11749 +3995 + +5298 +1877 +2065 +10499 +3493 +2892 + +4172 +2913 +2288 +7358 +1065 +3030 +5316 +5023 +1876 +2610 +5309 +5175 + +6904 +9471 +1232 +1741 +2239 +8554 +6327 +6507 +7603 + +23962 +3536 + +3214 +1102 +3823 +1876 +3929 +4890 +5526 +3009 +2619 +1565 +3364 +1392 +2407 +3129 +3586 + +8438 +2649 +4887 +4306 +1675 +2870 +2014 +1160 +6542 +8475 + +10172 +1686 +5999 +9145 +10361 +7814 + +3049 +5192 +2091 +4788 +3460 +2701 +2441 +2485 +2440 +2256 +5054 +4631 +5652 +3636 +3827 + +5944 +7870 +2055 +9296 +7574 +8691 +8852 + +2178 +1658 +6451 +6725 +1093 +6265 +7412 +5641 +2348 +5377 +2680 + +6607 +13797 +10728 +6412 + +10824 +25891 +24424 + +2278 +3407 +1688 +6069 +2324 +1868 +6037 +2496 +3324 +5346 +4118 +3881 +5260 +2094 +2334 + +3330 +2884 +6186 +5513 +3483 +6790 +4571 +4173 +4569 +1909 +5574 + +2073 +2159 +1468 +6189 +2770 +5299 +2039 +4247 +6289 +5453 +3797 +1432 +5501 +2600 + +7484 +8409 +8216 +1966 +2720 +5125 +5532 +10092 + +3704 +4032 +13787 +14642 +6007 + +2893 +3724 +6947 +5569 +6284 +5015 +6589 +4359 +3846 +5402 +5771 +2995 + +3027 +2193 +4194 +6211 +4912 +4523 +3402 +4199 +4777 +5955 +3217 +6162 +1556 +5269 + +6162 +7433 +2853 +4649 +4505 +7220 +5276 +1873 +6655 +5549 +2992 + +3304 +3655 +2028 +4079 +5182 +6830 +3885 +2274 +2769 +2514 +2146 + +2616 +5717 +1758 +2847 +4579 +1853 +1556 +2043 +1293 +1566 +2327 +6678 +5738 + +17934 +19341 + +6652 +3289 +6927 +2152 +2094 +2458 +5635 +6927 +4626 +6846 +5324 +6085 +2571 + +4344 +6656 +3831 +4768 +12536 +13166 + +2696 +5427 +9429 +1393 +5758 +9578 +4958 + +6889 +3107 +1112 +3035 +4159 +3697 +4832 +2604 +6318 +2804 +4325 +5497 +4214 + +3588 +5313 +1330 +8568 +9017 +1794 +9578 +8426 +4836 + +31988 + +5561 +3355 +5593 +3448 +2235 +3836 +2375 +2690 +1704 +3729 +2626 +6329 +3297 +5067 + +4244 +1729 +1598 +1025 +5921 +3214 +2230 +4120 +1274 +1136 +5798 +4259 +2821 +1968 + +5291 +7790 +8452 +1235 +10438 +2069 +1365 +9288 + +5533 +4261 +6170 +1884 +5315 +2901 +3588 +2903 +2441 +2264 +3162 +4188 +3993 +1592 + +15202 +9385 +17135 +10731 + +4591 +2068 +1136 +4292 +4351 +2100 +6075 +4463 +5887 +4507 +1273 +3815 +3595 +4846 + +8033 +7540 +9200 +10554 +2572 +2148 +7195 +9335 + +6923 +4006 +5057 +1209 +5025 +4788 +2977 +3924 +1149 +5407 +3240 +4363 +2870 + +18428 +1484 +6717 + +21437 +10877 + +13896 +13142 +14976 +4279 +7760 + +3736 +3606 +6255 +1070 +4078 +1204 +4140 +5864 +5772 +3706 +4794 +1810 +3891 + +7568 +9015 +8576 +9630 +4006 +8770 +7403 +7606 +8039 + +3523 +5469 +4603 +7988 +6196 +6253 +7393 +7866 +1976 +8036 +1708 + +23475 + +58206 + +8598 +4206 +7981 +1145 +8057 +3214 +2519 +4155 +6886 +7736 + +10064 +5532 +4310 + +5605 +6163 +3079 +5633 +7550 +1557 +3957 +3829 +8064 +5976 + +14566 +2324 +11737 +8884 + +5741 +9973 +5120 +8385 +6468 +6446 + +12939 +7370 +11204 +3902 + +6531 +6059 +3199 +4544 +2988 +6196 +5805 +2947 +6562 +6497 +5311 +1092 +3929 + +2969 +5314 +5341 +7533 +1601 +9340 +1458 +4516 +1911 + +18278 +17057 +19676 +13319 + +1740 +1218 +7693 +7610 +1179 +2611 +2494 +1995 +2606 +3634 +4818 + +51246 + +7826 +5544 +5835 +5983 +5180 +7833 +8681 +7170 +1166 +7254 + +2013 +4870 +1732 +5678 +5275 +4257 +3686 +6372 +6335 +2539 +1566 +3028 +1304 +3809 + +4410 +6375 +5386 +7307 +2385 +6675 +1443 +5057 +4051 +5263 +4460 + +3437 +4993 +6230 +2211 +6522 +4888 +5539 +4875 +4449 +3257 +1333 +3603 + +1433 +4953 +4098 +10882 +8320 +11840 +10795 + +6925 +7292 +9340 +2198 +1406 +2490 +5490 +6380 +6512 + +4332 +2273 +3506 +6399 +3161 +2458 +4217 +2567 +4582 +2109 +4513 +5392 + +2597 +7554 +9150 +5701 +8972 +7443 +6788 +3224 + +6098 +7293 +6994 +8305 +7896 +2339 +3312 +7702 +3616 + +55975 + +2514 +10887 + +7264 +10835 +21533 + +6666 +1428 +6668 +7673 +2755 +3344 +5937 +6942 +7279 +7284 +3344 + +4809 + +4748 +7859 +5322 +3460 +3728 +2462 +7973 +1576 + +1207 +1949 +2608 +1448 +2317 +3410 +7804 +2404 +9159 + +38251 + +10983 +5513 +9496 +7341 +11958 +7265 + +10483 +7081 +5477 +12178 + +8421 +13928 +7231 +10781 +11620 + +7219 +2204 +5179 +5011 +4139 +2160 +6130 +1902 +5293 +8458 + +13895 +10711 +10857 +14214 + +9062 +4001 +8483 +4260 +9408 + +8856 +2473 +4738 +9554 +1238 +6186 +1747 +6853 +8308 + +6468 +5359 +8925 +7929 +9055 +6194 +4431 +4177 + +1452 +2594 +5079 +6108 +7286 +6997 +1052 +4952 +2458 +5843 +3390 + +59084 + +4350 +2892 +6057 +6449 +3274 +4882 +2824 +2625 +2761 +6381 +1803 +2641 +6303 +3518 + +4595 +15941 +14489 +12371 +13428 + +6748 +3113 +13130 +13855 +10202 + +4461 +4550 +3781 +5173 +2232 +3067 +3125 +3914 +5166 +4059 +1403 +1913 +2538 +5819 + +5492 +2956 +6397 +5485 +3908 +1764 +2853 +2690 +2751 +6816 +6510 +5134 +2251 + +1912 +11885 +9792 +9026 + +15319 +21333 +4765 + +1510 +1760 +1193 +5378 +5539 +1362 +3155 +6051 +3748 +5010 +4280 +1834 +5830 +1273 +2963 + +2625 +5173 +2499 +5779 +3165 +2148 +2098 +4888 +2787 +5898 +3977 +2740 +2160 +1791 +2522 + +20725 + +15813 +26702 + +1464 +3116 +7046 +5531 +13731 + +4178 +4204 +3722 +2109 +1772 +3920 +2560 +4029 +5846 +4360 +4538 +4889 +2312 +1086 +1093 + +1020 +3213 +1017 +3650 +4290 +2888 +4208 +2723 +4149 +2381 +3332 +1308 +2755 +4357 + +3010 +5317 +1507 +5472 +2171 +6005 +4331 +5355 +3211 +3797 +3963 +3738 +1899 +3390 +1455 + +2098 +6531 +3206 +4272 +7461 +5093 +5370 +5502 +1543 +4543 +5069 +3491 + +3195 +3617 +1509 +2926 +1668 +5901 +5893 +3950 +2428 +2572 +2390 +4899 +2234 +3937 +3111 + +6510 +1964 +6255 +1875 +5118 +3782 +3884 +5480 +2808 +4666 +2827 +3088 +3182 +3470 + +7230 +5126 +5584 +4880 +7753 +6132 +4098 +2893 +3148 +4209 +3646 + +2971 +2439 +2362 +6416 +5306 +2714 +4752 +6354 +4807 +3723 +4143 +6503 + +8492 +19004 +6323 + +5999 +7828 +7411 +4296 +8321 +5238 +5709 +5631 +6110 +1128 + +6126 +7809 +1458 +15754 +3603 + +8908 +8693 +8558 +3270 +5458 +12906 + +2463 +7423 +6250 +2029 +15528 + +5146 +6644 +1905 +6828 +2572 +4226 +6264 +4324 +3369 +5999 +5373 +5591 +6634 + +2053 +7877 +2218 +2415 +2090 +6433 +8607 +3502 +8313 +2841 + +5471 +5190 +4424 +5184 +3040 +5373 +4799 +8122 +1038 + +4988 +2833 +4461 +2976 +1168 +5195 +1043 +2270 +7339 +7435 +7226 +5779 + +11587 +6728 +6765 +11498 +4711 +3547 + +2878 +8426 +11717 +8591 +5481 +10803 +11181 + +4915 +2093 +6057 +6957 +13009 +12971 + +17979 +3250 +19984 + +5650 +5756 +3307 +10549 +6717 +9579 +2849 +6885 + +2609 +2347 +4692 +5000 +5068 +5148 +4337 +4316 +2654 +2221 +1822 + +13157 + +10140 +5075 +10446 +2946 +5902 +5856 +8096 +8762 + +16951 +9118 +17962 + +7524 +4389 +3716 +3580 +5930 +1197 +3233 +6070 +4612 +2477 +6792 + +6403 +11307 +10753 +9665 +4919 +6485 +3189 + +8790 +10424 +8816 +3840 +6236 +5529 +8946 +3864 + +1370 +4810 +3752 +1664 +1247 +3227 +4605 +4906 +5436 +4534 +4722 +4104 +5629 +4962 +3203 + +2120 +4830 +2859 +2828 +3020 +5260 +5795 +3286 +5247 +6126 +4156 +3624 +2730 + +58973 + +18871 +8511 + +13088 +1608 +12123 +5162 +9357 +2409 + +3194 +2605 +8440 +9642 +9067 +5709 +4431 +5553 + +10532 +36332 + +7227 +10011 +7519 +4030 +7444 +2693 +3845 + +10004 +5735 +9671 +3576 +7111 +1292 +10428 +2800 + +4229 +6072 +3748 +1466 +2305 +2664 +2612 +5054 +2625 +2778 +2712 +2788 +5133 + +10716 +11271 +11169 +9815 +1641 +1025 + +3016 +3916 +6618 +4213 +6968 +3525 +1944 +6525 +1920 +8741 + +19472 + +15684 +10706 +14780 +15411 +9358 + +5290 +8167 +5269 +7051 +2848 +3948 +5987 +4844 +7749 +5696 + +9032 +12663 +11173 +14750 + +1121 +2123 +6582 +5753 +6358 +2524 +6486 +2259 +2197 +1883 +3005 +2406 +5967 diff --git a/examples/aoc2022/day1/p1.vq b/examples/aoc2022/day1/p1.vq new file mode 100755 index 0000000..2030bb3 --- /dev/null +++ b/examples/aoc2022/day1/p1.vq @@ -0,0 +1,18 @@ +() lI'moH vulqangan cher + +0 2244 { + 'Ij latlh + tlheghjuv 0 rap'a' + wIv + { woD woD vulqangan muv lI'moH vulqangan cher 0 HIja' } HIja'chugh + { mI'moH boq } ghobe'chugh +} vangqa' + +vulqangan ghorqu' juv wa'boqHa' { + QI QI puS'a' + wIv + { woD tam woD HIja' } HIja'chugh + { woD } ghobe'chugh +} vangqa' + +cha' diff --git a/examples/aoc2022/day1/p1.vqe b/examples/aoc2022/day1/p1.vqe new file mode 100755 index 0000000..4bedee9 --- /dev/null +++ b/examples/aoc2022/day1/p1.vqe @@ -0,0 +1,18 @@ +() ~ elves set + +0 2244 { + listen dup + strmeasure 0 eq? + choose + { pop pop elves cons ~ elves set 0 true } ifyes + { numberize add } ifno +} repeat + +elves shatter depth sub1 { + over over lt? + choose + { pop exch pop true } ifyes + { pop } ifno +} repeat + +disp diff --git a/examples/aoc2022/day1/p2.vqe b/examples/aoc2022/day1/p2.vqe new file mode 100755 index 0000000..4bedee9 --- /dev/null +++ b/examples/aoc2022/day1/p2.vqe @@ -0,0 +1,18 @@ +() ~ elves set + +0 2244 { + listen dup + strmeasure 0 eq? + choose + { pop pop elves cons ~ elves set 0 true } ifyes + { numberize add } ifno +} repeat + +elves shatter depth sub1 { + over over lt? + choose + { pop exch pop true } ifyes + { pop } ifno +} repeat + +disp diff --git a/examples/list.vqe b/examples/list.vqe new file mode 100755 index 0000000..a04f24c --- /dev/null +++ b/examples/list.vqe @@ -0,0 +1 @@ +(1 2 3 4 "test this" pi(*test*)) empty? disp diff --git a/examples/test.vqe b/examples/test.vqe index 072bce9..579283e 100755 --- a/examples/test.vqe +++ b/examples/test.vqe @@ -18,8 +18,6 @@ listen strtie disp - (1 2 3 4 "test this" pi(*test*)) - num 1 add ~ num set num disp } name diff --git a/varaq/interpreter.go b/varaq/interpreter.go index b4b3239..f3a4a69 100755 --- a/varaq/interpreter.go +++ b/varaq/interpreter.go @@ -1,6 +1,7 @@ package varaq import ( + "bufio" "fmt" "math" "math/rand" @@ -13,6 +14,7 @@ import ( var globals = map[string]Expr{} var stack = make([]Expr, 0) +var s = bufio.NewScanner(os.Stdin) func get(k string) Expr { return globals[k] @@ -127,6 +129,10 @@ func Interpret(code Expr, argv []string) error { push(c) case FUNCTION: push(c) + case TRUE: + push(Expr{BOOLEAN, nil, true, 0}) + case FALSE: + push(Expr{BOOLEAN, nil, false, 0}) case POP: _, e := pop() if e != nil { @@ -150,6 +156,22 @@ func Interpret(code Expr, argv []string) error { } push(obj1) push(obj2) + case OVER: + n := len(stack) - 1 + if n-1 < 0 { + return fmt.Errorf("over: stack underflow") + } + push(stack[n-1]) + case ROT: + n := len(stack) - 1 + if n-3 < 0 { + return fmt.Errorf("stack underflow, must have 3 or more") + } + + push(stack[n-2]) + stack = append(stack[:n-2], stack[n-3:]...) + case DEPTH: + push(Expr{NUMBER, nil, float64(len(stack)), 0}) case CLEAR: stack = nil stack = make([]Expr, 0) @@ -179,9 +201,10 @@ func Interpret(code Expr, argv []string) error { } } case DUMP: - for n := len(stack); n > 0; n-- { + for n := len(stack) - 1; n >= 0; n-- { fmt.Println(stack[n]) } + fmt.Println("=== end of dump ===") case NAME: fun, e := pop() if e != nil { @@ -320,7 +343,7 @@ func Interpret(code Expr, argv []string) error { return e } if list.Tok == LIST { - for n := 0; n < list.Count; n++ { + for n := 0; n < len(list.Exprs); n++ { push(list.Exprs[n]) } } else { @@ -332,7 +355,7 @@ func Interpret(code Expr, argv []string) error { return e } if list.Tok == LIST { - push(Expr{BOOLEAN, nil, list.Count == 0, 0}) + push(Expr{BOOLEAN, nil, len(list.Exprs) == 0, 0}) } else { return fmt.Errorf("cannot `shatter` not a list @%v", idx) } @@ -464,7 +487,7 @@ func Interpret(code Expr, argv []string) error { return e } if v.Tok == STRING { - push(Expr{NUMBER, nil, len(v.Value.(string)), 0}) + push(Expr{NUMBER, nil, float64(len(v.Value.(string))), 0}) } else { return fmt.Errorf("cannot `strmeasure` value is not a string @%v", idx) } @@ -1000,7 +1023,7 @@ func Interpret(code Expr, argv []string) error { } if a.Tok == NUMBER && b.Tok == NUMBER { - push(Expr{BOOLEAN, nil, a.Value.(float64) == (b.Value.(float64)), 0}) + push(Expr{BOOLEAN, nil, a.Value.(float64) == b.Value.(float64), 0}) } else { return fmt.Errorf("cannot `eq` values are not numbers @%v", idx) } @@ -1177,10 +1200,12 @@ func Interpret(code Expr, argv []string) error { } case LISTEN: var str string - _, err := fmt.Scanln(&str) - if err != nil { - return err + s.Scan() + str = s.Text() + + if s.Err() != nil { + return s.Err() } push(Expr{STRING, nil, str, 0}) case COMPLAIN: diff --git a/varaq/scanner.go b/varaq/scanner.go index 35ae03b..76692ab 100755 --- a/varaq/scanner.go +++ b/varaq/scanner.go @@ -10,7 +10,9 @@ import ( var keywords = map[string]TokenType{ "false": FALSE, + "ghobe'": FALSE, "true": TRUE, + "HIja'": TRUE, "pi": PI, "e": E, "pop": POP, @@ -121,7 +123,7 @@ var keywords = map[string]TokenType{ "law''a'": GT, "law'rap'a'": GE, "maHghurtaH": LOG, - "mi'moH": NUMBERIZE, + "mI'moH": NUMBERIZE, "muv": CONS, "mobmoH": ISOLATE, "mIScher": SETRAND, @@ -172,6 +174,13 @@ var keywords = map[string]TokenType{ "taghDe'": ARGV, "pongmI'": VERSION, "nuqDaq_jIH": WHEREAMI, + // All the ones after this are a part of the var'aq superset + "rot": ROT, + "jIr": ROT, + "over": OVER, + "QI": OVER, + "depth": DEPTH, + "juv": DEPTH, } func isDigit(s string) bool { diff --git a/varaq/token.go b/varaq/token.go index 18f2c10..e361a07 100755 --- a/varaq/token.go +++ b/varaq/token.go @@ -102,6 +102,9 @@ const ( ARGV TIME GARBAGECOLLECT + OVER + ROT + DEPTH ) var tokens = [...]string{ @@ -203,6 +206,9 @@ var tokens = [...]string{ ARGV: "ARGV", TIME: "TIME", GARBAGECOLLECT: "GARBAGECOLLECT", + OVER: "OVER", + ROT: "ROT", + DEPTH: "DEPTH", } func (me TokenType) String() string {