fix listen, dump; add over, rot, depth, aoc 2022
This commit is contained in:
parent
ef1d37cdfc
commit
ed6cf767d0
|
@ -0,0 +1,423 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>1 Language Overview</title>
|
||||||
|
<style>
|
||||||
|
/* From extension vscode.github */
|
||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
.vscode-dark img[src$=\#gh-light-mode-only],
|
||||||
|
.vscode-light img[src$=\#gh-dark-mode-only] {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* From extension ms-toolsai.jupyter */
|
||||||
|
/* These classnames are inherited from bootstrap, but are present in most notebook renderers */
|
||||||
|
|
||||||
|
.alert {
|
||||||
|
width: auto;
|
||||||
|
padding: 1em;
|
||||||
|
margin-top: 1em;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
}
|
||||||
|
.alert > *:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
#preview > .alert:last-child {
|
||||||
|
/* Prevent this being set to zero by the default notebook stylesheet */
|
||||||
|
padding-bottom: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alert-success {
|
||||||
|
/* Note there is no suitable color available, so we just copy "info" */
|
||||||
|
background-color: var(--theme-info-background);
|
||||||
|
color: var(--theme-info-foreground);
|
||||||
|
}
|
||||||
|
.alert-info {
|
||||||
|
background-color: var(--theme-info-background);
|
||||||
|
color: var(--theme-info-foreground);
|
||||||
|
}
|
||||||
|
.alert-warning {
|
||||||
|
background-color: var(--theme-warning-background);
|
||||||
|
color: var(--theme-warning-foreground);
|
||||||
|
}
|
||||||
|
.alert-danger {
|
||||||
|
background-color: var(--theme-error-background);
|
||||||
|
color: var(--theme-error-foreground);
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/markdown.css">
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/highlight.css">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', system-ui, 'Ubuntu', 'Droid Sans', sans-serif;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<style>
|
||||||
|
.task-list-item {
|
||||||
|
list-style-type: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-list-item-checkbox {
|
||||||
|
margin-left: -20px;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body class="vscode-body vscode-light">
|
||||||
|
<h1 id="varaq-specification"><em>var'aq</em> Specification</h1>
|
||||||
|
<p>For better flavor text please read the <a href="https://www.oocities.org/connorbd/varaq/varaqspec.html">Original <code>var'aq</code> spec</a> 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.</p>
|
||||||
|
<h2 id="1-language-overview">1 Language Overview</h2>
|
||||||
|
<p><em>var'aq</em> 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.</p>
|
||||||
|
<h3 id="12-filetypes">1.2 Filetypes</h3>
|
||||||
|
<ul>
|
||||||
|
<li><code>.vq -- application/varaq</code> -- a standard <em>var'aq</em> source file</li>
|
||||||
|
<li><code>.vqe -- application/varaq-engl</code> -- an English-keyword <em>var'aq</em> source file</li>
|
||||||
|
</ul>
|
||||||
|
<h2 id="2-language-basics">2 Language Basics</h2>
|
||||||
|
<p>This section describes the fundamental <em>var'aq</em> language constructs and data types.</p>
|
||||||
|
<h3 id="21-stack-operations">2.1 Stack Operations</h3>
|
||||||
|
<p>These operations directly manipulate the <em>var'aq</em> 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.</p>
|
||||||
|
<h4 id="211-popwod">2.1.1 pop/woD</h4>
|
||||||
|
<p><em>obj <code>woD</code> -</em></p>
|
||||||
|
<p>Pops and discards the top item on the stack. The literal meaning is <em>discard</em>.</p>
|
||||||
|
<p>Errors: stackUnderflow</p>
|
||||||
|
<h4 id="212-duplatlh">2.1.2 dup/latlh</h4>
|
||||||
|
<p><em>obj <code>latlh</code> obj obj</em></p>
|
||||||
|
<p>Duplicates the top object on the stack.</p>
|
||||||
|
<p>Errors: stackUnderflow</p>
|
||||||
|
<h4 id="213-exchtam">2.1.3 exch/tam</h4>
|
||||||
|
<p><em>obj1 obj2 <code>tam</code> obj2 obj1</em></p>
|
||||||
|
<p>Inverts the order of the top two objects on the stack.</p>
|
||||||
|
<p>Errors: stackUnderflow</p>
|
||||||
|
<h4 id="214-clearchimmoh">2.1.4 clear/chImmoH</h4>
|
||||||
|
<p><em>... obj <code>chIm</code> -</em></p>
|
||||||
|
<p>Empties the stack.</p>
|
||||||
|
<p>Errors: none</p>
|
||||||
|
<h4 id="215-rememberqaw">2.1.5 remember/qaw</h4>
|
||||||
|
<p><em>- <code>qaw</code> flag</em></p>
|
||||||
|
<p>Puts a flag (like PostScript's <code>mark</code>) on the stack. The internal representation of the flag is not available to the programmer.</p>
|
||||||
|
<p>Errors: none</p>
|
||||||
|
<h4 id="216-forgetqawha">2.1.6 forget/qawHa'</h4>
|
||||||
|
<p><em>... flag ... <code>qawHa'</code> ...</em></p>
|
||||||
|
<p>Clears the stack down to the flag and pops the flag. If there is no flag present, the stack is emptied completely.</p>
|
||||||
|
<p>Errors: none</p>
|
||||||
|
<h4 id="217-dumphotlh-lit-scan">2.1.7 dump/Hotlh (lit. scan)</h4>
|
||||||
|
<p><em>... <code>Hotlh</code> ...</em></p>
|
||||||
|
<p>Prints the contents of the operand stack to STDOUT without changing them. <em>Note</em>: the <em>Hotlh</em> 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 <em>var'aq</em> developer. In particular, the output format of this operator is implementation-defined and will not be specified in this document. <em>Hotlh</em> may be redefined to take such arguments as the implementor feels appropriate.</p>
|
||||||
|
<p>Errors: implementation-defined.</p>
|
||||||
|
<h4 id="218-disinter">2.1.8 disinter</h4>
|
||||||
|
<p>Returns the value just above the top mark on the stack without disturbing the stack above it.</p>
|
||||||
|
<h3 id="22-datacode-operations">2.2 Data/Code Operations</h3>
|
||||||
|
<p><em>var'aq</em>, 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.</p>
|
||||||
|
<h4 id="221--quotelimoh">2.2.1 ~ (quote/lI'moH)</h4>
|
||||||
|
<p><em>- <code>~</code> obj obj</em></p>
|
||||||
|
<p>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.)</p>
|
||||||
|
<p>The literal meaning of this operator's name is "make useful". Errors: none</p>
|
||||||
|
<h4 id="222-">2.2.2 {</h4>
|
||||||
|
<p>Begins the creation of an anonymous procedure. The process is implementation-dependent.</p>
|
||||||
|
<h4 id="223-">2.2.3 }</h4>
|
||||||
|
<p><em>- <code>}</code> proc</em></p>
|
||||||
|
<p>Completes procedure construction and pushes a reference to the completed procedure on the stack. Does not execute the procedure.</p>
|
||||||
|
<p>Errors: noDefinedProc</p>
|
||||||
|
<h4 id="224-namepong">2.2.4 name/pong</h4>
|
||||||
|
<p><em>obj id <code>pong</code> -</em></p>
|
||||||
|
<p>Associates <em>obj</em> with <em>id</em> and places it in the system lookup space. Conventionally used to associate new operator names with procedure objects.</p>
|
||||||
|
<p>Example: <em>~ add3 { boq boq cha' } pong</em></p>
|
||||||
|
<p>Pushes the name <em>add3</em> and a procedure object on the stack, then binds the name to the procedure.</p>
|
||||||
|
<p>Errors: stackUnderflow, noDefinedProc</p>
|
||||||
|
<h4 id="225-setcher">2.2.5 set/cher</h4>
|
||||||
|
<p><em>obj id <code>cher</code> -</em></p>
|
||||||
|
<p>Reassigns the value of a value already in the system lookup space. Used primarily for variable assignments.</p>
|
||||||
|
<p>Errors: stackUnderflow, noSuchName</p>
|
||||||
|
<h4 id="226----comment">2.2.6 (* ... *) (comment)</h4>
|
||||||
|
<p>Marks a comment in a program. All such comments are treated as single tokens and ignored.</p>
|
||||||
|
<h4 id="227-name">2.2.7 //<em>name</em></h4>
|
||||||
|
<p>Causes the interpreter to import a file with the name <em>name</em>.vq(e) and execute it as if it is part of the currently executing program. Essentially equivalent to <code>#include</code> in C.</p>
|
||||||
|
<p>An example can be found at the top of the <a href="./examples/test.vqe">test.vqe</a> example.</p>
|
||||||
|
<p><code>Note:</code> you must use either absolute paths or paths relitive to the location of the interpeter</p>
|
||||||
|
<h3 id="23-control-flow">2.3 Control Flow</h3>
|
||||||
|
<p><em>var'aq</em> supports a small but sufficient supply of conditional and iterative operators.</p>
|
||||||
|
<h4 id="231-ifyeshijachugh">2.3.1 ifyes/HIja'chugh</h4>
|
||||||
|
<p><em>bool proc <code>HIja'chugh</code> -</em></p>
|
||||||
|
<p>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.</p>
|
||||||
|
<p>Errors: stackUnderflow, noDefinedProc</p>
|
||||||
|
<h4 id="232-ifnoghobechugh">2.3.2 ifno/ghobe'chugh</h4>
|
||||||
|
<p><em>bool proc <code>ghobe'chugh</code> -</em></p>
|
||||||
|
<p>Similar to <em>HIja'chugh</em> above, but executes proc only if bool is false.</p>
|
||||||
|
<p>Errors: stackUnderFlow, noDefinedProc</p>
|
||||||
|
<h4 id="233-choosewiv">2.3.3 choose/wIv</h4>
|
||||||
|
<p><em>bool <code>wIv</code> bool bool</em></p>
|
||||||
|
<p>Duplicates a boolean value on top of the stack. Allows paired HI'ja'chugh/ghobe'chugh clauses.</p>
|
||||||
|
<p><code>Note:</code> 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.</p>
|
||||||
|
<h4 id="234-evalchov">2.3.4 eval/chov</h4>
|
||||||
|
<p><em>proc <code>chov</code> -</em></p>
|
||||||
|
<p>Pops a proc object off the stack and executes it.</p>
|
||||||
|
<p>Errors: stackUnderflow, noDefinedProc</p>
|
||||||
|
<h4 id="235-escapenargh">2.3.5 escape/nargh</h4>
|
||||||
|
<p><em>bool <code>nargh</code> -</em></p>
|
||||||
|
<p>Exit the current procedure. Useful for exit conditions on loops. Will terminate the current session if used top-level.</p>
|
||||||
|
<h4 id="236-repeatvangqa">2.3.6 repeat/vangqa'</h4>
|
||||||
|
<p><em>val proc <code>vangqa'</code> -</em></p>
|
||||||
|
<p>Pops val and proc off the stack and executes proc val times.</p>
|
||||||
|
<h3 id="24-list-operations">2.4 List Operations</h3>
|
||||||
|
<p><em>var'aq</em> supports a series of operators for management of lists (<em>ghomHom</em>, 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.</p>
|
||||||
|
<p>Note that "objects" as they stand in <em>var'aq</em> are largely singletons as in JavaScript; there is no inherent concept of object-orientation or anything like it in standard <em>var'aq</em>.</p>
|
||||||
|
<h4 id="241-">2.4.1 (</h4>
|
||||||
|
<p>Begins a list definition.</p>
|
||||||
|
<h4 id="242-">2.4.2 )</h4>
|
||||||
|
<p><em>( item1 item2 ... <code>)</code> list</em></p>
|
||||||
|
<p>Creates a list and pushes it onto the stack.</p>
|
||||||
|
<h4 id="243-splitsij">2.4.3 split/SIj</h4>
|
||||||
|
<p><em>list <code>SIj</code> item1 list</em></p>
|
||||||
|
<p>Pops a list off the stack and returns the first item and the rest of the list.</p>
|
||||||
|
<h4 id="244-consmuv">2.4.4 cons/muv</h4>
|
||||||
|
<p><em>list item1 ... <code>muv</code> list</em></p>
|
||||||
|
<p>Takes an object and adds it to the head of a list. Equivalent to the LISP <code>cons</code> operator.</p>
|
||||||
|
<h4 id="245-shatterghorqu">2.4.5 shatter/ghorqu'</h4>
|
||||||
|
<p><em>list <code>ghorqu'</code> item1 item2 ...</em></p>
|
||||||
|
<p>Reduces a list to its component elements and pushes them on the stack in order.</p>
|
||||||
|
<p><code>Note:</code> The precise meaning of the construction <em>ghorqu'</em> is a bit obscure; the rendering <em>shatter</em> is idiomatic and may derive from a nonstandard dialect. Standard Klingon would generally prefer <em>jor</em>, meaning <em>explode</em>.)</p>
|
||||||
|
<h4 id="246-emptychima">2.4.6 empty?/chIm'a'</h4>
|
||||||
|
<p><em>list <code>chIm'a'</code> bool</em></p>
|
||||||
|
<p>Examines a list on the stack and returns 1 if its value is null (<em>pagh</em>), a 0 if it contains anything.</p>
|
||||||
|
<h4 id="247-consume">2.4.7 consume</h4>
|
||||||
|
<p><em>obj1 obj2 ... mark <code>consume</code> list</em></p>
|
||||||
|
<p>Pops all objects on the stack down to <em>mark</em> and returns them in a list.</p>
|
||||||
|
<p><code>Note:</code> some implementations also have an operator known as bite/<em>chop</em>, equivalent to the Lisp <em>cdr</em>. This is not required in any standard <em>var'aq</em> implementation and can easily be rendered by the function</p>
|
||||||
|
<pre><code>~ chop { SIj woD } pong
|
||||||
|
</code></pre>
|
||||||
|
<h3 id="25-string-operators">2.5 String Operators</h3>
|
||||||
|
<p><em>tlheghjangwI'mey</em></p>
|
||||||
|
<h4 id="251-strtietlheghrar">2.5.1 strtie/tlheghrar</h4>
|
||||||
|
<p><em>str1 str2 <code>tlheghrar</code> str3</em></p>
|
||||||
|
<p>Concatenates the top two strings on the stack into one.</p>
|
||||||
|
<h4 id="252-composenaqmoh">2.5.2 compose/naQmoH</h4>
|
||||||
|
<p><em>mark str1 str2 ... strn <code>naQmoH</code> strn'</em></p>
|
||||||
|
<p>Pops objects (executing proc objects if necessary) off the stack until a marker (placed by <code>qaw</code>) is hit and combines them into one string.</p>
|
||||||
|
<h4 id="253-streqtlheghrapa">2.5.3 streq?/tlheghrap'a'</h4>
|
||||||
|
<p><em>str1 str2 <code>tlheghrap'a'</code> bool</em></p>
|
||||||
|
<p>Pops the top two strings on the stack, compares them, and returns 1 if identical, 0 if not.</p>
|
||||||
|
<h4 id="254-strcuttlheghpe">2.5.4 strcut/tlheghpe'</h4>
|
||||||
|
<p><em>str startval endval <code>tlheghpe'</code> substr</em></p>
|
||||||
|
<p>Pops two values and a string and returns the section of the string between character <em>startval</em> and character <em>endval</em>.</p>
|
||||||
|
<h4 id="255-strmeasuretlheghjuv">2.5.5 strmeasure/tlheghjuv</h4>
|
||||||
|
<p><em>str <code>tlheghjuv</code> val</em></p>
|
||||||
|
<p>Pops a string off the stack and returns its length in characters.</p>
|
||||||
|
<h4 id="256-explodejor">2.5.6 explode/jor</h4>
|
||||||
|
<p><em>str <code>jor</code> list</em></p>
|
||||||
|
<p>Separates individual "words" in a string by whitespace.</p>
|
||||||
|
<h2 id="3-mathematical-operators">3 Mathematical Operators</h2>
|
||||||
|
<p><em>mI'jangwI'mey</em></p>
|
||||||
|
<h3 id="31-arithmetic-operations">3.1 Arithmetic Operations</h3>
|
||||||
|
<p><em>toghwI'mey</em></p>
|
||||||
|
<p>Arithmetic operators usually work with real numbers unless otherwise stated. The number operators (sec 3.3) can convert them to integers if necessary.</p>
|
||||||
|
<h4 id="311-addboq">3.1.1 add/boq</h4>
|
||||||
|
<p><em>a b <code>boq</code> sum</em></p>
|
||||||
|
<p>Pops the top two values on the stack and replaces them with their sum.</p>
|
||||||
|
<h4 id="312-subboqha">3.1.2 sub/boqHa'</h4>
|
||||||
|
<p><em>a b <code>boqHa'</code> difference</em></p>
|
||||||
|
<p>Pops the top two values on the stack and replaces them with a - b.</p>
|
||||||
|
<h4 id="313-mulboqegh">3.1.3 mul/boq'egh</h4>
|
||||||
|
<p><em>a b <code>boq'egh</code> product</em></p>
|
||||||
|
<p>Pops the top two values on the stack and replaces them with their product.</p>
|
||||||
|
<h4 id="314-divboqhaegh">3.1.4 div/boqHa''egh</h4>
|
||||||
|
<p><em>a b <code>wav</code> quotient</em></p>
|
||||||
|
<p>Pops the top two values on the stack and replaces them with a/b.</p>
|
||||||
|
<h4 id="315-idivhabboqhaegh-lit-full-divide">3.1.5 idiv/HabboqHa''egh (lit. full-divide)</h4>
|
||||||
|
<p><em>a b <code>HabboqHa''egh</code> quotient</em></p>
|
||||||
|
<p>Pops the top two values on the stack and replaces them with the results of an integer division operation.</p>
|
||||||
|
<h4 id="316-modchuv-lit-leftover">3.1.6 mod/chuv (lit. leftover)</h4>
|
||||||
|
<p><em>a b <code>chuv</code> remainder</em></p>
|
||||||
|
<p>Pops the top two values and returns the remainder of a mod b.</p>
|
||||||
|
<h4 id="317-powboqhaqa-lit-remultiply">3.1.7 pow/boqHa'qa' (lit. remultiply)</h4>
|
||||||
|
<p><em>base exp <code>boqHa'qa'</code> real</em></p>
|
||||||
|
<p>Pops the top two values and returns base^exp.</p>
|
||||||
|
<h4 id="318-sqrtlosar-lit-fourth-howmuch">3.1.8 sqrt/loS'ar (lit. fourth-howmuch)</h4>
|
||||||
|
<p><em>angle <code>loS'ar</code> real</em></p>
|
||||||
|
<p>Returns the square root of val.</p>
|
||||||
|
<h4 id="319-add1waboq">3.1.9 add1/wa'boq</h4>
|
||||||
|
<p><em>a <code>wa'boq</code> a+1</em></p>
|
||||||
|
<p>Increments the top value on the stack by one.</p>
|
||||||
|
<h4 id="3110-sub1waboqha">3.1.10 sub1/wa'boqHa'</h4>
|
||||||
|
<p><em>a <code>wa'boqHa'</code> a-1</em></p>
|
||||||
|
<p>Decrements the top value on the stack by one.</p>
|
||||||
|
<h3 id="32-trigonometric-and-logarithmic-operators">3.2 Trigonometric and Logarithmic Operators</h3>
|
||||||
|
<p><em>SIHpojjangwI'mey 'ej ghurjangwI'mey</em></p>
|
||||||
|
<h4 id="321-sinyuegh-lit-wave">3.2.1 sin/yu'egh (lit. wave)</h4>
|
||||||
|
<p><em>angle <code>yu'egh</code> real</em></p>
|
||||||
|
<p>Returns the sine of val.</p>
|
||||||
|
<h4 id="322-cosyueghha-lit-counter-wave">3.2.2 cos/yu'eghHa' (lit. counter-wave)</h4>
|
||||||
|
<p><em>angle <code>yu'eghHa'</code> cos(val)</em></p>
|
||||||
|
<p>Returns the cosine of val.</p>
|
||||||
|
<h4 id="323-tanqojmi-lit-cliffnumber">3.2.3 tan/qojmI' (lit. cliffnumber)</h4>
|
||||||
|
<p><em>angle <code>qojmI'</code> tan(val)</em></p>
|
||||||
|
<p>Returns the tangent of val.</p>
|
||||||
|
<h4 id="324-atanqojha-lit-anticliff">3.2.4 atan/qojHa' (lit. anticliff)</h4>
|
||||||
|
<p><em>num den <code>qojHa'</code> angle</em></p>
|
||||||
|
<p>Returns the arctangent of <em>num / den</em>.</p>
|
||||||
|
<h4 id="325-lnghurtah">3.2.5 ln/ghurtaH</h4>
|
||||||
|
<p><em>num <code>ghurtaH</code> real</em></p>
|
||||||
|
<p>Returns the natural log of <em>num</em>.</p>
|
||||||
|
<h4 id="326-logmahghurtah">3.2.6 log/maHghurtaH</h4>
|
||||||
|
<p><em>num <code>maHghurtaH</code> real</em></p>
|
||||||
|
<p>Returns the base 10 log of <em>num</em>.</p>
|
||||||
|
<h4 id="327-log3wejghurtah">3.2.7 log3/wejghurtaH</h4>
|
||||||
|
<p><em>num <code>wejghurtaH</code> real</em></p>
|
||||||
|
<p>Returns the base 3 log of <em>num</em>.</p>
|
||||||
|
<h3 id="33-numerical-operators-and-constants">3.3 Numerical Operators and Constants</h3>
|
||||||
|
<p>This section describes operators that operate on numbers themselves, as well as common system-level constants.</p>
|
||||||
|
<h4 id="331-clippod">3.3.1 clip/poD</h4>
|
||||||
|
<p><em>real <code>poD</code> int</em></p>
|
||||||
|
<p>Removes the fractional portion of a real number (equivalent to floor(real).</p>
|
||||||
|
<h4 id="332-smoothhab-lit-smooth">3.3.2 smooth/Hab (lit. smooth)</h4>
|
||||||
|
<p><em>real <code>Hab</code> int</em></p>
|
||||||
|
<p>Rounds a number to the nearest integer.</p>
|
||||||
|
<h4 id="333-howmuchar">3.3.3 howmuch/'ar</h4>
|
||||||
|
<p><em>num <code>'ar</code> num2</em></p>
|
||||||
|
<p>Returns the absolute value of <em>num</em>.</p>
|
||||||
|
<h4 id="334-setrandmischer">3.3.4 setrand/mIScher</h4>
|
||||||
|
<p><em>num <code>mIScher</code> -</em></p>
|
||||||
|
<p>Sets the random number generator seed value to <em>num</em>. Not common, since most <em>var'aq</em> implementations have a rather arcane formula for picking a pseudo-random seed value.</p>
|
||||||
|
<h4 id="335-randmis">3.3.5 rand/mIS</h4>
|
||||||
|
<p><em>num <code>mIS</code> real</em></p>
|
||||||
|
<p>Returns a random real number in the range 0 to <em>num</em>. If there is no meaningful input on the stack,</p>
|
||||||
|
<h4 id="336-pihehmi">3.3.6 pi/HeHmI'</h4>
|
||||||
|
<p>Pushes the value pi (~3.14159...) onto the stack. The Klingon name literally means "edge-number".</p>
|
||||||
|
<h4 id="337-eghurmi">3.3.7 e/ghurmI'</h4>
|
||||||
|
<p>Pushes the value e onto the stack. The Klingon name literally means "growth-number".</p>
|
||||||
|
<h4 id="338-inthabmia">3.3.8 int?/HabmI''a'</h4>
|
||||||
|
<p><em>val <code>HabmI''a'</code> bool</em> Pops the top value on the stack and returns 1 if it is an integer, 0 if not.</p>
|
||||||
|
<h4 id="339-numbermia">3.3.9 number?/mI''a'</h4>
|
||||||
|
<p><em>val <code>mI''a'</code> bool</em></p>
|
||||||
|
<p>Pops the top value off the stack and returns 1 if it's a number, 0 if it's something else.</p>
|
||||||
|
<h4 id="3310-numberizemimoh">3.3.10 numberize/mI'moH</h4>
|
||||||
|
<p><em>str <code>mi'moH</code> val</em></p>
|
||||||
|
<p>Pops a string off the stack, converts it into a numerical value, and returns it.</p>
|
||||||
|
<h4 id="34-bitwise-operators">3.4 Bitwise operators</h4>
|
||||||
|
<p>Though <em>var'aq</em> 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.</p>
|
||||||
|
<h4 id="341-isolatemobmoh">3.4.1 isolate/mobmoH</h4>
|
||||||
|
<p><em>a b <code>mobmoH</code> result</em></p>
|
||||||
|
<p>Performs a bitwise AND on a and b.</p>
|
||||||
|
<h4 id="342-mixdud">3.4.2 mix/DuD</h4>
|
||||||
|
<p><em>a b <code>DuD</code> result</em></p>
|
||||||
|
<p>Performs a bitwise OR on a and b.</p>
|
||||||
|
<h4 id="343-contradicttlhoch">3.4.3 contradict/tlhoch</h4>
|
||||||
|
<p><em>a b <code>tlhoch</code> result</em></p>
|
||||||
|
<p>Performs a bitwise XOR on a and b.</p>
|
||||||
|
<h4 id="344-complqomoh">3.4.4 compl/Qo'moH</h4>
|
||||||
|
<p><em>val <code>Qo'moH</code> ~val</em></p>
|
||||||
|
<p>Returns the one's-complement of val. <code>Note:</code> The literal meaning is something like "make it say no".</p>
|
||||||
|
<h4 id="345-shiftrightnihghos">3.4.5 shiftright/nIHghoS</h4>
|
||||||
|
<p><em>a b <code>nIHghoS</code> result</em></p>
|
||||||
|
<p>Shifts a right b places, preserving the sign of the value.</p>
|
||||||
|
<h4 id="346-shiftleftposghos">3.4.6 shiftleft/poSghoS</h4>
|
||||||
|
<p><em>a b <code>poSghoS</code> result</em></p>
|
||||||
|
<p>Shifts a left b places.</p>
|
||||||
|
<h3 id="4-relational-and-logical-operators">4 Relational and Logical Operators</h3>
|
||||||
|
<h4 id="41-relational-operators-and-predicate-functions">4.1 Relational Operators and Predicate Functions</h4>
|
||||||
|
<p><em>yu'jangwI'mey</em></p>
|
||||||
|
<h4 id="411-gtlawa">4.1.1 gt?/law''a'</h4>
|
||||||
|
<p><em>a b <code>law''a'</code> bool</em></p>
|
||||||
|
<p>Pops a and b off the stack, compares them, and returns a boolean value of true if a is larger.</p>
|
||||||
|
<h4 id="412-ltpusa">4.1.2 lt?/puS'a'</h4>
|
||||||
|
<p><em>a b <code>puS'a'</code> bool</em></p>
|
||||||
|
<p>Pops a and b off the stack, compares them, and returns a boolean value of true if a is smaller.</p>
|
||||||
|
<h4 id="413-eqrapa">4.1.3 eq?/rap'a'</h4>
|
||||||
|
<p><em>a b <code>rap'a'</code> bool</em></p>
|
||||||
|
<p>Pops a and b off the stack, compares them, and returns a boolean value of true if a is the same as b.</p>
|
||||||
|
<h4 id="414-gelawrapa">4.1.4 ge?/law'rap'a'</h4>
|
||||||
|
<p><em>a b <code>law'rap'a'</code> bool</em></p>
|
||||||
|
<p>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.</p>
|
||||||
|
<h4 id="415-lepusrapa">4.1.5 le?/puSrap'a'</h4>
|
||||||
|
<p><em>a b <code>puSrap'a'</code> bool</em></p>
|
||||||
|
<p>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.</p>
|
||||||
|
<h4 id="416-nerapbea">4.1.6 ne?/rapbe'a'</h4>
|
||||||
|
<p><em>a b <code>rapbe'a'</code> bool</em></p>
|
||||||
|
<p>Pops a and b off the stack, compares them, and returns a boolean value of true if a is not equal to b.</p>
|
||||||
|
<h4 id="417-nullpagha">4.1.7 null?/pagh'a'</h4>
|
||||||
|
<p><em>obj <code>pagh'a'</code> bool</em></p>
|
||||||
|
<p>Examines the top object on the stack and returns a 1 if null, a 0 if not.</p>
|
||||||
|
<h4 id="418-negativetaha">4.1.8 negative?/taH'a'</h4>
|
||||||
|
<p><em>val <code>taH'a'</code> bool</em></p>
|
||||||
|
<p>Pops the top number on the stack and returns a 1 if less than 0, a 0 if not.</p>
|
||||||
|
<h4 id="42-logical-operators">4.2 Logical Operators</h4>
|
||||||
|
<p><em>vItjangwI'mey</em></p>
|
||||||
|
<p>Note that these are strictly logical operators, not bitwise.</p>
|
||||||
|
<h4 id="421-andje">4.2.1 and/je</h4>
|
||||||
|
<p><em>a b <code>je</code> bool</em></p>
|
||||||
|
<p>Evaluates b and a and returns a 1 if both are true, a 0 if not.</p>
|
||||||
|
<h4 id="422-orjoq">4.2.2 or/joq</h4>
|
||||||
|
<p><em>a b <code>joq</code> bool</em></p>
|
||||||
|
<p>Evaluates b and a and returns a 1 if one or both are true, a 0 if both are false.</p>
|
||||||
|
<h4 id="423-xorghap">4.2.3 xor/ghap</h4>
|
||||||
|
<p><em>a b <code>ghap</code> bool</em></p>
|
||||||
|
<p>Evaluates b and a and returns a 1 if only one is true, a 0 otherwise.</p>
|
||||||
|
<h4 id="424-notghobe">4.2.4 not/ghobe'</h4>
|
||||||
|
<p><em>val <code>ghobe'</code> bool</em></p>
|
||||||
|
<p>Evaluates val and returns 1 if true, 0 if not.</p>
|
||||||
|
<h3 id="5-inputoutput-and-file-operators">5 Input/Output and File Operators</h3>
|
||||||
|
<p>The <em>var'aq</em> Level 0 specification essentially handles console I/O and files in a manner very similar to the UNIX model.</p>
|
||||||
|
<h4 id="51-console-io">5.1 Console I/O</h4>
|
||||||
|
<p>The console I/O model at this point is very simple: write, read, error.</p>
|
||||||
|
<h4 id="511-dispcha">5.1.1 disp/cha'</h4>
|
||||||
|
<p><em>obj <code>cha'</code> -</em></p>
|
||||||
|
<p>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.</p>
|
||||||
|
<h4 id="512-listenij">5.1.2 listen/'Ij</h4>
|
||||||
|
<p><em>- <code>'Ij</code> str</em></p>
|
||||||
|
<p>Reads one line of input and stores it as a string on top of the stack.</p>
|
||||||
|
<h4 id="513-complainbep">5.1.3 complain/bep</h4>
|
||||||
|
<p><em>str <code>bep</code> -</em></p>
|
||||||
|
<p>Pops <em>str</em> and prints it to stderr.</p>
|
||||||
|
<h3 id="6-system-variables">6 System Variables</h3>
|
||||||
|
<p><em>patSarwI'mey</em></p>
|
||||||
|
<p>This section describes <em>var'aq</em> keywords that do no more than put set values on the stack. Many of them are not precisely constants but more like environment variables.</p>
|
||||||
|
<h4 id="61-io-related-constants">6.1 I/O-related Constants</h4>
|
||||||
|
<h4 id="611-newlinechudonwi">6.1.1 newline/chu'DonwI'</h4>
|
||||||
|
<p><em>- <code>chu'DonwI'</code> '\n'</em></p>
|
||||||
|
<p>Prints a carriage return.</p>
|
||||||
|
<h4 id="612-tabchutut">6.1.2 tab/chu'tut</h4>
|
||||||
|
<p><em>- <code>chu'DonwI'</code> '\t'</em></p>
|
||||||
|
<p>Advances by one tab stop.</p>
|
||||||
|
<h4 id="62-environment-constants">6.2 Environment Constants</h4>
|
||||||
|
<h4 id="621-whereaminuqdaq_jih">6.2.1 whereami/nuqDaq_jIH</h4>
|
||||||
|
<p><em>- <code>nuqDaq_jIH</code> "string of your local ip address"</em></p>
|
||||||
|
<p>Returns the IP address of the machine the interpreter is running on.</p>
|
||||||
|
<h4 id="622-versionpongmi">6.2.2 version/pongmI'</h4>
|
||||||
|
<p><em>- <code>pongmI'</code> "string of version"</em></p>
|
||||||
|
<p>Returns the current interpreter version number. The reference interpreter returns a date stamp.</p>
|
||||||
|
<h4 id="623-argvtaghde">6.2.3 argv/taghDe'</h4>
|
||||||
|
<p><em>- <code>taghDe'</code> (arg1, arg2, ...)</em></p>
|
||||||
|
<p>Pushes the command line arguments on the stack as a list.</p>
|
||||||
|
<h2 id="7-new-operators">7 New Operators</h2>
|
||||||
|
<p>The following are all new operators that are not included in the original perl implementation of <em>var'aq</em></p>
|
||||||
|
<h3 id="71-stack-operations">7.1 Stack Operations</h3>
|
||||||
|
<p>These are stolen directly from <em>Forth</em> (specifically the <a href="http://www.forth.org/Ting/Forth-for-the-Complete-Idiot/Forth-79-Handy-Reference.pdf"><em>FORTH-79 Handy Reference</em></a> from the book <em>Forth for the Complete Idiot</em>),</p>
|
||||||
|
<p>They are very useful for doing operations without clobbering the stack</p>
|
||||||
|
<h4 id="711-overqi">7.1.1 over/QI</h4>
|
||||||
|
<p><em>obj1 obj2 <code>QI</code> obj1 obj2 obj1</em></p>
|
||||||
|
<p>Make a copy of the second item on top of the stack.</p>
|
||||||
|
<p>The direct Klingon translation for <code>QI</code> is bridge, as in a bridge over a river, which works close enough.</p>
|
||||||
|
<p>Errors: stackUnderflow</p>
|
||||||
|
<h4 id="712-rotjir">7.1.2 rot/jIr</h4>
|
||||||
|
<p><em>obj1 obj2 obj3 <code>jIr</code> obj2 obj3 obj1</em></p>
|
||||||
|
<p>Rotate the third item to the top of the stack.</p>
|
||||||
|
<p>Errors: stackUnderflow</p>
|
||||||
|
<h4 id="713-depthjuv">7.1.3 depth/juv</h4>
|
||||||
|
<p><em>- <code>juv</code> num</em></p>
|
||||||
|
<p>Count the number of items on the stack and push that number to the top of the stack.</p>
|
||||||
|
<p>Errors: stackUnderflow</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
45
SPEC.md
45
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'
|
#### 6.1.1 newline/chu'DonwI'
|
||||||
|
|
||||||
|
_- `chu'DonwI'` '\n'_
|
||||||
|
|
||||||
Prints a carriage return.
|
Prints a carriage return.
|
||||||
|
|
||||||
#### 6.1.2 tab/chu'tut
|
#### 6.1.2 tab/chu'tut
|
||||||
|
|
||||||
|
_- `chu'DonwI'` '\t'_
|
||||||
|
|
||||||
Advances by one tab stop.
|
Advances by one tab stop.
|
||||||
|
|
||||||
#### 6.2 Environment Constants
|
#### 6.2 Environment Constants
|
||||||
|
|
||||||
#### 6.2.1 whereami/nuqDaq\_jIH
|
#### 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.
|
Returns the IP address of the machine the interpreter is running on.
|
||||||
|
|
||||||
#### 6.2.2 version/pongmI'
|
#### 6.2.2 version/pongmI'
|
||||||
|
|
||||||
|
_- `pongmI'` "string of version"_
|
||||||
|
|
||||||
Returns the current interpreter version number. The reference interpreter returns a date stamp.
|
Returns the current interpreter version number. The reference interpreter returns a date stamp.
|
||||||
|
|
||||||
#### 6.2.3 argv/taghDe'
|
#### 6.2.3 argv/taghDe'
|
||||||
|
|
||||||
|
_- `taghDe'` (arg1, arg2, ...)_
|
||||||
|
|
||||||
Pushes the command line arguments on the stack as a list.
|
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
|
||||||
|
|
38
build.sh
38
build.sh
|
@ -1,37 +1 @@
|
||||||
GOOS=plan9 GOARCH=386 go build -o bin/varaq-plan9-386 main.go
|
go build -o bin/varaq 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
|
|
||||||
|
|
|
@ -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
|
File diff suppressed because it is too large
Load Diff
|
@ -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'
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1 @@
|
||||||
|
(1 2 3 4 "test this" pi(*test*)) empty? disp
|
|
@ -18,8 +18,6 @@
|
||||||
listen strtie
|
listen strtie
|
||||||
disp
|
disp
|
||||||
|
|
||||||
(1 2 3 4 "test this" pi(*test*))
|
|
||||||
|
|
||||||
num 1 add ~ num set
|
num 1 add ~ num set
|
||||||
num disp
|
num disp
|
||||||
} name
|
} name
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package varaq
|
package varaq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
@ -13,6 +14,7 @@ import (
|
||||||
|
|
||||||
var globals = map[string]Expr{}
|
var globals = map[string]Expr{}
|
||||||
var stack = make([]Expr, 0)
|
var stack = make([]Expr, 0)
|
||||||
|
var s = bufio.NewScanner(os.Stdin)
|
||||||
|
|
||||||
func get(k string) Expr {
|
func get(k string) Expr {
|
||||||
return globals[k]
|
return globals[k]
|
||||||
|
@ -127,6 +129,10 @@ func Interpret(code Expr, argv []string) error {
|
||||||
push(c)
|
push(c)
|
||||||
case FUNCTION:
|
case FUNCTION:
|
||||||
push(c)
|
push(c)
|
||||||
|
case TRUE:
|
||||||
|
push(Expr{BOOLEAN, nil, true, 0})
|
||||||
|
case FALSE:
|
||||||
|
push(Expr{BOOLEAN, nil, false, 0})
|
||||||
case POP:
|
case POP:
|
||||||
_, e := pop()
|
_, e := pop()
|
||||||
if e != nil {
|
if e != nil {
|
||||||
|
@ -150,6 +156,22 @@ func Interpret(code Expr, argv []string) error {
|
||||||
}
|
}
|
||||||
push(obj1)
|
push(obj1)
|
||||||
push(obj2)
|
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:
|
case CLEAR:
|
||||||
stack = nil
|
stack = nil
|
||||||
stack = make([]Expr, 0)
|
stack = make([]Expr, 0)
|
||||||
|
@ -179,9 +201,10 @@ func Interpret(code Expr, argv []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case DUMP:
|
case DUMP:
|
||||||
for n := len(stack); n > 0; n-- {
|
for n := len(stack) - 1; n >= 0; n-- {
|
||||||
fmt.Println(stack[n])
|
fmt.Println(stack[n])
|
||||||
}
|
}
|
||||||
|
fmt.Println("=== end of dump ===")
|
||||||
case NAME:
|
case NAME:
|
||||||
fun, e := pop()
|
fun, e := pop()
|
||||||
if e != nil {
|
if e != nil {
|
||||||
|
@ -320,7 +343,7 @@ func Interpret(code Expr, argv []string) error {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
if list.Tok == LIST {
|
if list.Tok == LIST {
|
||||||
for n := 0; n < list.Count; n++ {
|
for n := 0; n < len(list.Exprs); n++ {
|
||||||
push(list.Exprs[n])
|
push(list.Exprs[n])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -332,7 +355,7 @@ func Interpret(code Expr, argv []string) error {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
if list.Tok == LIST {
|
if list.Tok == LIST {
|
||||||
push(Expr{BOOLEAN, nil, list.Count == 0, 0})
|
push(Expr{BOOLEAN, nil, len(list.Exprs) == 0, 0})
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("cannot `shatter` not a list @%v", idx)
|
return fmt.Errorf("cannot `shatter` not a list @%v", idx)
|
||||||
}
|
}
|
||||||
|
@ -464,7 +487,7 @@ func Interpret(code Expr, argv []string) error {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
if v.Tok == STRING {
|
if v.Tok == STRING {
|
||||||
push(Expr{NUMBER, nil, len(v.Value.(string)), 0})
|
push(Expr{NUMBER, nil, float64(len(v.Value.(string))), 0})
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("cannot `strmeasure` value is not a string @%v", idx)
|
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 {
|
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 {
|
} else {
|
||||||
return fmt.Errorf("cannot `eq` values are not numbers @%v", idx)
|
return fmt.Errorf("cannot `eq` values are not numbers @%v", idx)
|
||||||
}
|
}
|
||||||
|
@ -1177,10 +1200,12 @@ func Interpret(code Expr, argv []string) error {
|
||||||
}
|
}
|
||||||
case LISTEN:
|
case LISTEN:
|
||||||
var str string
|
var str string
|
||||||
_, err := fmt.Scanln(&str)
|
|
||||||
|
|
||||||
if err != nil {
|
s.Scan()
|
||||||
return err
|
str = s.Text()
|
||||||
|
|
||||||
|
if s.Err() != nil {
|
||||||
|
return s.Err()
|
||||||
}
|
}
|
||||||
push(Expr{STRING, nil, str, 0})
|
push(Expr{STRING, nil, str, 0})
|
||||||
case COMPLAIN:
|
case COMPLAIN:
|
||||||
|
|
|
@ -10,7 +10,9 @@ import (
|
||||||
|
|
||||||
var keywords = map[string]TokenType{
|
var keywords = map[string]TokenType{
|
||||||
"false": FALSE,
|
"false": FALSE,
|
||||||
|
"ghobe'": FALSE,
|
||||||
"true": TRUE,
|
"true": TRUE,
|
||||||
|
"HIja'": TRUE,
|
||||||
"pi": PI,
|
"pi": PI,
|
||||||
"e": E,
|
"e": E,
|
||||||
"pop": POP,
|
"pop": POP,
|
||||||
|
@ -121,7 +123,7 @@ var keywords = map[string]TokenType{
|
||||||
"law''a'": GT,
|
"law''a'": GT,
|
||||||
"law'rap'a'": GE,
|
"law'rap'a'": GE,
|
||||||
"maHghurtaH": LOG,
|
"maHghurtaH": LOG,
|
||||||
"mi'moH": NUMBERIZE,
|
"mI'moH": NUMBERIZE,
|
||||||
"muv": CONS,
|
"muv": CONS,
|
||||||
"mobmoH": ISOLATE,
|
"mobmoH": ISOLATE,
|
||||||
"mIScher": SETRAND,
|
"mIScher": SETRAND,
|
||||||
|
@ -172,6 +174,13 @@ var keywords = map[string]TokenType{
|
||||||
"taghDe'": ARGV,
|
"taghDe'": ARGV,
|
||||||
"pongmI'": VERSION,
|
"pongmI'": VERSION,
|
||||||
"nuqDaq_jIH": WHEREAMI,
|
"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 {
|
func isDigit(s string) bool {
|
||||||
|
|
|
@ -102,6 +102,9 @@ const (
|
||||||
ARGV
|
ARGV
|
||||||
TIME
|
TIME
|
||||||
GARBAGECOLLECT
|
GARBAGECOLLECT
|
||||||
|
OVER
|
||||||
|
ROT
|
||||||
|
DEPTH
|
||||||
)
|
)
|
||||||
|
|
||||||
var tokens = [...]string{
|
var tokens = [...]string{
|
||||||
|
@ -203,6 +206,9 @@ var tokens = [...]string{
|
||||||
ARGV: "ARGV",
|
ARGV: "ARGV",
|
||||||
TIME: "TIME",
|
TIME: "TIME",
|
||||||
GARBAGECOLLECT: "GARBAGECOLLECT",
|
GARBAGECOLLECT: "GARBAGECOLLECT",
|
||||||
|
OVER: "OVER",
|
||||||
|
ROT: "ROT",
|
||||||
|
DEPTH: "DEPTH",
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me TokenType) String() string {
|
func (me TokenType) String() string {
|
||||||
|
|
Loading…
Reference in New Issue