mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
Compare commits
74 Commits
master-fai
...
test
| Author | SHA1 | Date | |
|---|---|---|---|
| 27cd520ea6 | |||
| 458317e193 | |||
|
|
046f569042 | ||
| 6b804f58d2 | |||
| 583e28b2f7 | |||
| 4020598315 | |||
| 43ae6dd1e2 | |||
| 0e4d057e2f | |||
| 035df80758 | |||
| fc8916ce4b | |||
| 488766159a | |||
|
|
9bfda2fb30 | ||
|
|
9bfb983c2b | ||
|
|
590d5cbc6e | ||
|
|
d574529eb7 | ||
| 5e7f246933 | |||
|
|
45e4135d82 | ||
| e2390e8d85 | |||
| e42a0da486 | |||
| ee0cb1fed9 | |||
| 79e4126785 | |||
| 65a7e35fb4 | |||
| 346c602a6c | |||
| 4a66d3937e | |||
| e810810c48 | |||
| 5cea62fcb4 | |||
| bf40ff3611 | |||
| 975436615d | |||
| 83346521bc | |||
| c6f13ce7a2 | |||
| ccdf8c03ee | |||
| b2bd683e08 | |||
| ab94c9ff65 | |||
| 7aa4a83cd1 | |||
| 32d76d1693 | |||
| 0f2a9b34e9 | |||
| 44e261bf70 | |||
| aa21a53791 | |||
| 425b73b681 | |||
| 32f810e9b0 | |||
| 4d37d8d4de | |||
| 88129528f4 | |||
| af934e0429 | |||
| 9649c33217 | |||
| 2012605d2b | |||
| 85e2964471 | |||
| 5bb89a86a7 | |||
| 6ff2d7c69f | |||
| 4ca158cc96 | |||
| f63229c6f8 | |||
| 9b3f3d1555 | |||
| ef951afab5 | |||
| 1d3eaf9990 | |||
| 1a2ad64ea4 | |||
| b8ceafa3c9 | |||
| a8cbfa66e9 | |||
| 114cdec821 | |||
| 9fe8bcb515 | |||
| ae08f059fb | |||
| 6495e7f9b9 | |||
| 40a1404534 | |||
| ad3ef3b673 | |||
| 3cec4a2339 | |||
| e7ab5c9b7e | |||
| 2ef823580d | |||
| 3bf48079d5 | |||
| 3f048ce645 | |||
| dc2e62bbdb | |||
| 82b14f09a3 | |||
| 14ae68b9d1 | |||
| 63d7616053 | |||
| 651830ec31 | |||
| 3071da2e2d | |||
| ec53db45d5 |
45
.github/workflows/build_releases.yml
vendored
Normal file
45
.github/workflows/build_releases.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
name: Build and Release Go Binary
|
||||
|
||||
on:
|
||||
release:
|
||||
types:
|
||||
- created
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build and Release
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.20 # Use your desired Go version
|
||||
|
||||
- name: Build Go project
|
||||
run: go build -o argon ./src
|
||||
|
||||
- name: Create release
|
||||
id: create_release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ github.ref }}
|
||||
release_name: Release ${{ github.ref }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
|
||||
- name: Upload binary to release
|
||||
id: upload-release-asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./argon
|
||||
asset_name: argon
|
||||
asset_content_type: application/octet-stream
|
||||
32
.github/workflows/go.yml
vendored
Normal file
32
.github/workflows/go.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
# This workflow will build a golang project
|
||||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
|
||||
|
||||
name: Go
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install or Update CA Certificates
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install -y --reinstall ca-certificates
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.20'
|
||||
- name: Build
|
||||
run: ./build
|
||||
|
||||
- name: Test
|
||||
run: go test -v ./src
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
||||
bin
|
||||
array.json
|
||||
argon_modules
|
||||
.DS_Store
|
||||
29
Dockerfile
Normal file
29
Dockerfile
Normal file
@@ -0,0 +1,29 @@
|
||||
# Use Alpine as the base image
|
||||
FROM golang:alpine
|
||||
|
||||
# Install isotope
|
||||
FROM ugric/isotope:latest
|
||||
|
||||
# Set the Current Working Directory inside the container
|
||||
WORKDIR /argon
|
||||
|
||||
# Copy go mod and sum files
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
|
||||
RUN go mod download
|
||||
|
||||
# Copy the source from the current directory to the Working Directory inside the container
|
||||
COPY ./src ./src
|
||||
|
||||
# Copy License
|
||||
COPY LICENSE .
|
||||
|
||||
# Build the Go app
|
||||
RUN go build -trimpath -ldflags="-s -w" -o bin/argon ./src
|
||||
|
||||
# make the binary executable
|
||||
RUN chmod +x bin/argon
|
||||
|
||||
# add the binary to the path
|
||||
ENV PATH="/argon/bin:${PATH}"
|
||||
674
LICENSE
Normal file
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
46
app.py
46
app.py
@@ -1,46 +0,0 @@
|
||||
def interpret(code):
|
||||
memory = {}
|
||||
pointer = 0
|
||||
code_ptr = 0
|
||||
loops = []
|
||||
|
||||
while code_ptr < len(code):
|
||||
command = code[code_ptr]
|
||||
|
||||
if command == '>':
|
||||
pointer += 1
|
||||
elif command == '<':
|
||||
pointer -= 1
|
||||
elif command == '+':
|
||||
if pointer not in memory:
|
||||
memory[pointer] = 0
|
||||
memory[pointer] += 1
|
||||
elif command == '-':
|
||||
if pointer not in memory:
|
||||
memory[pointer] = 0
|
||||
memory[pointer] -= 1
|
||||
elif command == '.':
|
||||
print(chr(memory.get(pointer, 0)), end='')
|
||||
elif command == ',':
|
||||
memory[pointer] = ord(input())
|
||||
elif command == '[':
|
||||
if memory.get(pointer, 0) == 0:
|
||||
loop_depth = 1
|
||||
while loop_depth > 0:
|
||||
code_ptr += 1
|
||||
if code[code_ptr] == '[':
|
||||
loop_depth += 1
|
||||
elif code[code_ptr] == ']':
|
||||
loop_depth -= 1
|
||||
else:
|
||||
loops.append(code_ptr)
|
||||
elif command == ']':
|
||||
if memory.get(pointer, 0) != 0:
|
||||
code_ptr = loops[-1]
|
||||
else:
|
||||
loops.pop()
|
||||
code_ptr += 1
|
||||
|
||||
# Example usage
|
||||
interpret("++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.")
|
||||
# Output: Hello World!
|
||||
4
argon-package.json
Normal file
4
argon-package.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "argon-v3",
|
||||
"version": "3.0.1"
|
||||
}
|
||||
2
build
2
build
@@ -1 +1 @@
|
||||
GOOS=js GOARCH=wasm go build -o wasm/bin/argon.wasm ./src
|
||||
go build -trimpath -ldflags="-s -w" -o bin/argon ./src
|
||||
@@ -1,4 +1,2 @@
|
||||
@echo off
|
||||
set GOOS=js
|
||||
set GOARCH=wasm
|
||||
go build -o wasm/bin/argon.wasm ./src
|
||||
go build -trimpath -ldflags="-s -w" -o bin/argon.exe ./src
|
||||
2
debug
Executable file
2
debug
Executable file
@@ -0,0 +1,2 @@
|
||||
# run the go run command passing the path to the main.go file, with the working directory set to the bin folder. pass in the arguments
|
||||
__ARGON_DEBUG__=true go run ./src "$@"
|
||||
6
debug.bat
Normal file
6
debug.bat
Normal file
@@ -0,0 +1,6 @@
|
||||
@echo off
|
||||
|
||||
:: run the go run command passing the path to the main.go file, with the working directory set to the bin folder. pass in the arguments
|
||||
|
||||
set __ARGON_DEBUG__=true
|
||||
go run ./src %*
|
||||
2
debug_build.bat
Normal file
2
debug_build.bat
Normal file
@@ -0,0 +1,2 @@
|
||||
@echo off
|
||||
go build -o bin/debug_argon.exe ./src
|
||||
1
dockerBuild
Executable file
1
dockerBuild
Executable file
@@ -0,0 +1 @@
|
||||
docker build -t ugric/argon .
|
||||
1
dockerPush
Executable file
1
dockerPush
Executable file
@@ -0,0 +1 @@
|
||||
docker push ugric/argon
|
||||
@@ -1,2 +0,0 @@
|
||||
forever do
|
||||
term.log(random())
|
||||
7
go.mod
7
go.mod
@@ -7,6 +7,13 @@ require (
|
||||
github.com/wadey/go-rounding v1.1.0
|
||||
)
|
||||
|
||||
require github.com/joho/godotenv v1.5.1 // indirect
|
||||
|
||||
require (
|
||||
github.com/gabriel-vasile/mimetype v1.4.2
|
||||
golang.org/x/net v0.8.0 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/jwalton/go-supportscolor v1.1.0
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
|
||||
4
go.sum
4
go.sum
@@ -1,5 +1,9 @@
|
||||
github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
|
||||
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
||||
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/jwalton/go-supportscolor v1.1.0 h1:HsXFJdMPjRUAx8cIW6g30hVSFYaxh9yRQwEWgkAR7lQ=
|
||||
github.com/jwalton/go-supportscolor v1.1.0/go.mod h1:hFVUAZV2cWg+WFFC4v8pT2X/S2qUUBYMioBD9AINXGs=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
|
||||
1
iso-lock.json
Normal file
1
iso-lock.json
Normal file
@@ -0,0 +1 @@
|
||||
[{"Name":"welcome","Version":"1.0.0","URL":"http://isotope.wbell.dev/isotope-download?name=welcome\u0026version=1.0.0","Remote":"isotope.wbell.dev"},{"Name":"this","Version":"1.0.0","URL":"http://isotope.wbell.dev/isotope-download?name=this\u0026version=1.0.0","Remote":"isotope.wbell.dev"},{"Name":"csv.ar","Version":"1.0.0","URL":"http://isotope.wbell.dev/isotope-download?name=csv.ar\u0026version=1.0.0","Remote":"isotope.wbell.dev"}]
|
||||
21
licence
21
licence
@@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 Open Argon
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,27 +0,0 @@
|
||||
let read(path) = do
|
||||
f = file.read(path)
|
||||
text = f.text()
|
||||
data = []
|
||||
splitlines = text.split("\n")
|
||||
for (i from 0 to splitlines.length) do
|
||||
values = []
|
||||
in_quotes = false
|
||||
start = 0
|
||||
line = splitlines[i]
|
||||
for (j from 0 to line.length) do
|
||||
char = line[j]
|
||||
if (char == "," && not in_quotes) do
|
||||
value = line[start:j].rightstrip("\r").strip()
|
||||
if (value && value[0] == "\"" && value[-1] == "\"") value = value[1:value.length - 1]
|
||||
value = value.replace("\"\"", "\"")
|
||||
values.append(value)
|
||||
start = j + 1
|
||||
else if (char == "\"") in_quotes = not in_quotes
|
||||
if (j == line.length - 1) do
|
||||
value = line[start:j + 1].rightstrip("\r").strip()
|
||||
if (value && value[0] == "\"" && value[-1] == "\"") value = value[1:value.length - 1]
|
||||
value = value.replace("\"\"", "\"")
|
||||
values.append(value)
|
||||
data.append(values)
|
||||
|
||||
return data
|
||||
@@ -1,53 +0,0 @@
|
||||
# The Argon Manifesto - ChatGPT
|
||||
|
||||
# Simple is better than complex
|
||||
# Argon's design, we should respect
|
||||
# Readability is key, it's plain to see
|
||||
# With Argon, code clarity comes naturally
|
||||
|
||||
# Sparse is better than dense
|
||||
# Argon's syntax, it makes sense
|
||||
# No need for excess, or verbosity
|
||||
# With Argon, brevity is a necessity
|
||||
|
||||
# Explicit is better than implicit
|
||||
# Argon's logic, it's not cryptic
|
||||
# Avoiding confusion, it's a must
|
||||
# With Argon, understanding is a trust
|
||||
|
||||
# Errors should never pass silently
|
||||
# Argon catches them, and does so quietly
|
||||
# Graceful handling, it's what we aim to achieve
|
||||
# With Argon, bugs are easier to perceive
|
||||
|
||||
# That which is complex, can be made simple
|
||||
# Argon's power, it's in its example
|
||||
# Programming, it can be a breeze
|
||||
# With Argon, it's a language that's sure to please
|
||||
|
||||
term.log("The Argon Manifesto - ChatGPT")
|
||||
term.log()
|
||||
term.log("Simple is better than complex")
|
||||
term.log("Argon's design, we should respect")
|
||||
term.log("Readability is key, it's plain to see")
|
||||
term.log("With Argon, code clarity comes naturally")
|
||||
term.log()
|
||||
term.log("Sparse is better than dense")
|
||||
term.log("Argon's syntax, it makes sense")
|
||||
term.log("No need for excess, or verbosity")
|
||||
term.log("With Argon, brevity is a necessity")
|
||||
term.log()
|
||||
term.log("Explicit is better than implicit")
|
||||
term.log("Argon's logic, it's not cryptic")
|
||||
term.log("Avoiding confusion, it's a must")
|
||||
term.log("With Argon, understanding is a trust")
|
||||
term.log()
|
||||
term.log("Errors should never pass silently")
|
||||
term.log("Argon catches them, and does so quietly")
|
||||
term.log("Graceful handling, it's what we aim to achieve")
|
||||
term.log("With Argon, bugs are easier to perceive")
|
||||
term.log()
|
||||
term.log("That which is complex, can be made simple")
|
||||
term.log("Argon's power, it's in its example")
|
||||
term.log("Programming, it can be a breeze")
|
||||
term.log("With Argon, it's a language that's sure to please")
|
||||
22
readme.md
22
readme.md
@@ -2,24 +2,12 @@
|
||||
<p>
|
||||
<img width="150" src="logos/ArLogo.png">
|
||||
</p>
|
||||
<h1>Argon v3.wasm</h1>
|
||||
<h1>Argon v3</h1>
|
||||
</div>
|
||||
|
||||
### HEADS UP! 🙂
|
||||
|
||||
Argon v3.wasm is a fork of Argon v3 which has had parts rewritten for support in WebAssembly (WASM).
|
||||
|
||||
It includes all the same features and functionality as Argon v3, but has been compiled to run efficiently on WebAssembly.
|
||||
|
||||
Please note that Argon v3.wasm can only be compiled for use with WebAssembly.
|
||||
|
||||
|
||||
---
|
||||
|
||||
ARGON 3 is a math-driven programming language designed to make code easy to read and write. It's not meant to be fast, as it's interpreted. This specification should be used as a guideline, and is subject to change for later versions. Later updates for Argon 3 should be backwards compatible (where possible) with code designed for older versions of the interpreter.
|
||||
|
||||
## 📚 Features
|
||||
|
||||
- Easy to read and write: Argon 3 is designed with clarity of code in mind, making it easier for you and others to read and write code.
|
||||
- All numbers are stored as rational numbers, preventing precision errors.
|
||||
- Math-driven: Designed for mathematical computations, Argon 3 uses techniques and rules set in maths. It's designed to be easy for mathematicians to write and understand algorithms in.
|
||||
@@ -28,11 +16,9 @@ ARGON 3 is a math-driven programming language designed to make code easy to read
|
||||
- Lightweight: The Argon 3 interpreter is small and doesn't require a lot of system resources to run.
|
||||
|
||||
## 💻 Installation
|
||||
|
||||
As of now, Argon 3 does not have an installer. Feel free to clone this repo and run the `build` file for your plateform. the build will be found in `bin/argon(.exe)`.
|
||||
|
||||
## 📖 Usage
|
||||
|
||||
To use Argon 3, you can create a file with the .ar extension and write your code in it. Then, you can run your code using the interpreter. For example, if you have a file called example.ar, you can run it using the following command:
|
||||
|
||||
```
|
||||
@@ -41,7 +27,7 @@ argon example.ar
|
||||
|
||||
## 🔍 Specification
|
||||
|
||||
For a detailed specification of the Argon 3 language, please refer to [spec.md](spec.md).
|
||||
For a detailed specification of the Argon 3 language, please refer to [the docs](https://argon.wbell.dev/docs/).
|
||||
|
||||
## 🚀 Example Code
|
||||
|
||||
@@ -52,10 +38,10 @@ f(x) = x^2 + 2*x + 1
|
||||
term.log('f(10) =', f(10))
|
||||
```
|
||||
|
||||
This code defines a function f(x) that calculates x^2 + 2\*x + 1. It then calls the function with an argument of 10 and logs the result to the console.
|
||||
This code defines a function f(x) that calculates x^2 + 2*x + 1. It then calls the function with an argument of 10 and logs the result to the console.
|
||||
|
||||
Please note that this example is subject to change as the specification is in beta and may be updated frequently.
|
||||
|
||||
## Licence
|
||||
|
||||
MIT
|
||||
GNU General Public License v3.0
|
||||
|
||||
2
run
Executable file
2
run
Executable file
@@ -0,0 +1,2 @@
|
||||
# run the go run command passing the path to the main.go file, with the working directory set to the bin folder. pass in the arguments
|
||||
go run ./src "$@"
|
||||
5
run.bat
Normal file
5
run.bat
Normal file
@@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
|
||||
:: run the go run command passing the path to the main.go file, with the working directory set to the bin folder. pass in the arguments
|
||||
|
||||
go run ./src %*
|
||||
64
src/array.go
64
src/array.go
@@ -115,6 +115,7 @@ func ArArray(arr []any) ArObject {
|
||||
step = int(a[2].(number).Num().Int64())
|
||||
}
|
||||
}
|
||||
var ogStart = start
|
||||
if start < 0 {
|
||||
start = len(arr) + start
|
||||
}
|
||||
@@ -124,6 +125,13 @@ func ArArray(arr []any) ArObject {
|
||||
if end != nil && end.(int) > len(arr) {
|
||||
end = len(arr)
|
||||
}
|
||||
if start >= len(arr) || start < 0 {
|
||||
return "", ArErr{
|
||||
TYPE: "IndexError",
|
||||
message: "index out of range, trying to access index " + fmt.Sprint(ogStart) + " in array of length " + fmt.Sprint(len(arr)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if end == nil {
|
||||
return arr[start], ArErr{}
|
||||
} else if step == 1 {
|
||||
@@ -313,7 +321,7 @@ func ArArray(arr []any) ArObject {
|
||||
}
|
||||
}
|
||||
arr = append(arr, args[0].(ArObject).obj["__value__"].([]any)...)
|
||||
val.obj["length"] = len(arr)
|
||||
val.obj["length"] = newNumber().SetUint64(uint64(len(arr)))
|
||||
val.obj["__value__"] = arr
|
||||
return nil, ArErr{}
|
||||
},
|
||||
@@ -356,8 +364,13 @@ func ArArray(arr []any) ArObject {
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
if reverse {
|
||||
for i, j := 0, len(output)-1; i < j; i, j = i+1, j-1 {
|
||||
output[i], output[j] = output[j], output[i]
|
||||
}
|
||||
}
|
||||
arr = output
|
||||
val.obj["length"] = len(arr)
|
||||
val.obj["length"] = newNumber().SetUint64(uint64(len(arr)))
|
||||
val.obj["__value__"] = arr
|
||||
return nil, ArErr{}
|
||||
}
|
||||
@@ -373,7 +386,7 @@ func ArArray(arr []any) ArObject {
|
||||
}
|
||||
}
|
||||
arr = output
|
||||
val.obj["length"] = len(arr)
|
||||
val.obj["length"] = newNumber().SetUint64(uint64(len(arr)))
|
||||
val.obj["__value__"] = arr
|
||||
return nil, ArErr{}
|
||||
},
|
||||
@@ -533,7 +546,7 @@ func ArArray(arr []any) ArObject {
|
||||
},
|
||||
}
|
||||
val.obj["__Equal__"] = builtinFunc{
|
||||
"__LessThanEqual__",
|
||||
"__Equal__",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{
|
||||
@@ -574,7 +587,7 @@ func ArArray(arr []any) ArObject {
|
||||
}
|
||||
for _, v := range arr {
|
||||
res, err := runOperation(operationType{
|
||||
operation: 8,
|
||||
operation: 9,
|
||||
values: []any{v, args[0]},
|
||||
}, stack{}, 0)
|
||||
if err.EXISTS {
|
||||
@@ -587,6 +600,47 @@ func ArArray(arr []any) ArObject {
|
||||
return false, ArErr{}
|
||||
},
|
||||
}
|
||||
val.obj["__NotContains__"] = builtinFunc{
|
||||
"__NotContains__",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "missing argument",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
for _, v := range arr {
|
||||
res, err := runOperation(operationType{
|
||||
operation: 9,
|
||||
values: []any{v, args[0]},
|
||||
}, stack{}, 0)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
if anyToBool(res) {
|
||||
return false, ArErr{}
|
||||
}
|
||||
}
|
||||
return true, ArErr{}
|
||||
},
|
||||
}
|
||||
val.obj["copy"] = builtinFunc{
|
||||
"copy",
|
||||
func(args ...any) (any, ArErr) {
|
||||
arrCopy := make([]any, len(arr))
|
||||
copy(arrCopy, arr)
|
||||
return ArArray(arrCopy), ArErr{}
|
||||
},
|
||||
}
|
||||
val.obj["__Boolean__"] = builtinFunc{
|
||||
"__Boolean__",
|
||||
func(args ...any) (any, ArErr) {
|
||||
return len(
|
||||
arr,
|
||||
) > 0, ArErr{}
|
||||
},
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@ func AnyToArValid(arr any) any {
|
||||
return ArString(arr)
|
||||
case anymap:
|
||||
return Map(arr)
|
||||
case []byte:
|
||||
return ArBuffer(arr)
|
||||
case byte:
|
||||
return ArByte(arr)
|
||||
default:
|
||||
return arr
|
||||
}
|
||||
@@ -22,3 +26,20 @@ func ArValidToAny(a any) any {
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func ArValidToHash(a any) (any, ArErr) {
|
||||
switch a := a.(type) {
|
||||
case ArObject:
|
||||
if callable, ok := a.obj["__hash__"]; ok {
|
||||
value, err := runCall(call{
|
||||
Callable: callable,
|
||||
Args: []any{},
|
||||
}, stack{}, 0)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
return value, ArErr{}
|
||||
}
|
||||
}
|
||||
return a, ArErr{}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func anyToBool(x any) bool {
|
||||
switch x := x.(type) {
|
||||
@@ -13,10 +15,18 @@ func anyToBool(x any) bool {
|
||||
case nil:
|
||||
return false
|
||||
case ArObject:
|
||||
if typeof(x) == "array" {
|
||||
return len(x.obj["__value__"].([]any)) != 0
|
||||
if y, ok := x.obj["__Boolean__"]; ok {
|
||||
val, err := runCall(
|
||||
call{
|
||||
Callable: y,
|
||||
Args: []any{},
|
||||
}, stack{}, 0)
|
||||
if err.EXISTS {
|
||||
return false
|
||||
}
|
||||
return len(x.obj) != 0
|
||||
return anyToBool(val)
|
||||
}
|
||||
return false
|
||||
case builtinFunc:
|
||||
return true
|
||||
case Callable:
|
||||
|
||||
506
src/buffer.go
Normal file
506
src/buffer.go
Normal file
@@ -0,0 +1,506 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func ArByte(Byte byte) ArObject {
|
||||
obj := ArObject{
|
||||
obj: anymap{
|
||||
"__name__": "byte",
|
||||
"__value__": Byte,
|
||||
},
|
||||
}
|
||||
obj.obj["__string__"] = builtinFunc{
|
||||
"__string__",
|
||||
func(a ...any) (any, ArErr) {
|
||||
return "<byte>", ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["__repr__"] = builtinFunc{
|
||||
"__repr__",
|
||||
func(a ...any) (any, ArErr) {
|
||||
return "<byte>", ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["number"] = builtinFunc{
|
||||
"number",
|
||||
func(a ...any) (any, ArErr) {
|
||||
return newNumber().SetInt64(int64(Byte)), ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["from"] = builtinFunc{
|
||||
"from",
|
||||
func(a ...any) (any, ArErr) {
|
||||
if len(a) == 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected at least 1 argument, got 0",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
a[0] = ArValidToAny(a[0])
|
||||
switch x := a[0].(type) {
|
||||
case number:
|
||||
if x.Denom().Cmp(one.Denom()) != 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected integer, got " + fmt.Sprint(x),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
n := x.Num().Int64()
|
||||
if n > 255 || n < 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "ValueError",
|
||||
message: "expected number between 0 and 255, got " + fmt.Sprint(floor(x).Num().Int64()),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
Byte = byte(n)
|
||||
case string:
|
||||
if len(x) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "ValueError",
|
||||
message: "expected string of length 1, got " + fmt.Sprint(len(x)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
Byte = byte(x[0])
|
||||
default:
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected number or string, got " + typeof(x),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return obj, ArErr{}
|
||||
},
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
func ArBuffer(buf []byte) ArObject {
|
||||
obj := ArObject{
|
||||
obj: anymap{
|
||||
"__name__": "buffer",
|
||||
"__value__": buf,
|
||||
"length": newNumber().SetInt64(int64(len(buf))),
|
||||
},
|
||||
}
|
||||
obj.obj["__string__"] = builtinFunc{
|
||||
"__string__",
|
||||
func(a ...any) (any, ArErr) {
|
||||
return "<buffer>", ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["__repr__"] = builtinFunc{
|
||||
"__repr__",
|
||||
func(a ...any) (any, ArErr) {
|
||||
return "<buffer>", ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["from"] = builtinFunc{
|
||||
"from",
|
||||
func(a ...any) (any, ArErr) {
|
||||
if len(a) == 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected at least 1 argument, got 0",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
a[0] = ArValidToAny(a[0])
|
||||
switch x := a[0].(type) {
|
||||
case string:
|
||||
buf = []byte(x)
|
||||
case []byte:
|
||||
buf = x
|
||||
case []any:
|
||||
outputbuf := []byte{}
|
||||
for _, v := range x {
|
||||
switch y := v.(type) {
|
||||
case number:
|
||||
if y.Denom().Cmp(one.Denom()) != 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "Cannot convert non-integer to byte",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
outputbuf = append(outputbuf, byte(y.Num().Int64()))
|
||||
default:
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "Cannot convert " + typeof(v) + " to byte",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
buf = outputbuf
|
||||
default:
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected string or buffer, got " + typeof(x),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
obj.obj["__value__"] = buf
|
||||
obj.obj["length"] = newNumber().SetInt64(int64(len(buf)))
|
||||
return obj, ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["splitN"] = builtinFunc{
|
||||
"splitN",
|
||||
func(a ...any) (any, ArErr) {
|
||||
if len(a) != 2 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
splitVal := ArValidToAny(a[0])
|
||||
if typeof(splitVal) != "buffer" {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected buffer, got " + typeof(splitVal),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
var separator = splitVal.([]byte)
|
||||
nVal := ArValidToAny(a[1])
|
||||
if typeof(nVal) != "number" {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected number, got " + typeof(nVal),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
nNum := nVal.(number)
|
||||
if nNum.Denom().Cmp(one.Denom()) != 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected integer, got " + fmt.Sprint(nNum),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
n := nNum.Num().Int64()
|
||||
var result [][]byte
|
||||
start := 0
|
||||
var i int64
|
||||
for i = 0; i < n; i++ {
|
||||
index := bytes.Index(buf[start:], separator)
|
||||
if index == -1 {
|
||||
result = append(result, buf[start:])
|
||||
break
|
||||
}
|
||||
end := start + index
|
||||
result = append(result, buf[start:end])
|
||||
start = end + len(separator)
|
||||
}
|
||||
|
||||
if int64(len(result)) != n {
|
||||
result = append(result, buf[start:])
|
||||
}
|
||||
var bufoutput = []any{}
|
||||
for _, v := range result {
|
||||
bufoutput = append(bufoutput, ArBuffer(v))
|
||||
}
|
||||
return ArArray(bufoutput), ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["split"] = builtinFunc{
|
||||
"split",
|
||||
func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
splitVal := ArValidToAny(a[0])
|
||||
if typeof(splitVal) != "buffer" {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected buffer, got " + typeof(splitVal),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
var separator = splitVal.([]byte)
|
||||
var result [][]byte
|
||||
start := 0
|
||||
|
||||
for {
|
||||
index := bytes.Index(buf[start:], separator)
|
||||
if index == -1 {
|
||||
result = append(result, buf[start:])
|
||||
break
|
||||
}
|
||||
end := start + index
|
||||
result = append(result, buf[start:end])
|
||||
start = end + len(separator)
|
||||
}
|
||||
var bufoutput = []any{}
|
||||
for _, v := range result {
|
||||
bufoutput = append(bufoutput, ArBuffer(v))
|
||||
}
|
||||
return ArArray(bufoutput), ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["slice"] = builtinFunc{
|
||||
"slice",
|
||||
func(a ...any) (any, ArErr) {
|
||||
if len(a) != 2 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected 2 arguments, got " + fmt.Sprint(len(a)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
startVal := ArValidToAny(a[0])
|
||||
if typeof(startVal) != "number" {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected number, got " + typeof(startVal),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
start := startVal.(number)
|
||||
if start.Denom().Cmp(one.Denom()) != 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected integer, got " + fmt.Sprint(start),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
endVal := ArValidToAny(a[1])
|
||||
if typeof(endVal) != "number" {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected number, got " + typeof(endVal),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
end := endVal.(number)
|
||||
if end.Denom().Cmp(one.Denom()) != 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected integer, got " + fmt.Sprint(end),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return ArBuffer(buf[floor(start).Num().Int64():floor(end).Num().Int64()]), ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["to"] = builtinFunc{
|
||||
"to",
|
||||
func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if typeof(a[0]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected string, got " + typeof(a[0]),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
Type := ArValidToAny(a[0]).(string)
|
||||
switch Type {
|
||||
case "string":
|
||||
return ArString(string(buf)), ArErr{}
|
||||
case "bytes":
|
||||
output := []any{}
|
||||
for _, v := range buf {
|
||||
output = append(output, ArByte(v))
|
||||
}
|
||||
return ArArray(output), ArErr{}
|
||||
case "array":
|
||||
output := []any{}
|
||||
for _, v := range buf {
|
||||
output = append(output, newNumber().SetInt64(int64(v)))
|
||||
}
|
||||
return ArArray(output), ArErr{}
|
||||
default:
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected string, bytes or array, got '" + Type + "'",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
obj.obj["append"] = builtinFunc{
|
||||
"append",
|
||||
func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
a[0] = ArValidToAny(a[0])
|
||||
switch x := a[0].(type) {
|
||||
case number:
|
||||
if x.Denom().Cmp(one.Denom()) != 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "Cannot convert non-integer to byte",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
buf = append(buf, byte(x.Num().Int64()))
|
||||
case string:
|
||||
buf = append(buf, []byte(x)...)
|
||||
case []byte:
|
||||
buf = append(buf, x...)
|
||||
case []any:
|
||||
for _, v := range x {
|
||||
switch y := v.(type) {
|
||||
case number:
|
||||
if y.Denom().Cmp(one.Denom()) != 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "Cannot convert non-integer to byte",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
buf = append(buf, byte(y.Num().Int64()))
|
||||
default:
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "Cannot convert " + typeof(v) + " to byte",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected string, buffer or array, got " + typeof(x),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
obj.obj["__value__"] = buf
|
||||
obj.obj["length"] = newNumber().SetInt64(int64(len(buf)))
|
||||
return obj, ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["insert"] = builtinFunc{
|
||||
"insert",
|
||||
func(a ...any) (any, ArErr) {
|
||||
if len(a) != 2 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected 2 arguments, got " + fmt.Sprint(len(a)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
poss := ArValidToAny(a[0])
|
||||
values := ArValidToAny(a[1])
|
||||
if typeof(poss) != "number" {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected number, got " + typeof(poss),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
pos := poss.(number)
|
||||
if pos.Denom().Cmp(one.Denom()) != 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "position must be an integer",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
posNum := pos.Num().Int64()
|
||||
switch x := values.(type) {
|
||||
case number:
|
||||
if x.Denom().Cmp(one.Denom()) != 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "Cannot convert non-integer to byte",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
buf = append(buf[:posNum], append([]byte{byte(x.Num().Int64())}, buf[posNum:]...)...)
|
||||
case string:
|
||||
buf = append(buf[:posNum], append([]byte(x), buf[posNum:]...)...)
|
||||
case []byte:
|
||||
buf = append(buf[:posNum], append(x, buf[posNum:]...)...)
|
||||
case []any:
|
||||
for _, v := range x {
|
||||
switch y := v.(type) {
|
||||
case number:
|
||||
if y.Denom().Cmp(one.Denom()) != 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "Cannot convert non-integer to byte",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
buf = append(buf[:posNum], append([]byte{byte(y.Num().Int64())}, buf[posNum:]...)...)
|
||||
default:
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "Cannot convert " + typeof(v) + " to byte",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected string or buffer, got " + typeof(x),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
obj.obj["__value__"] = buf
|
||||
obj.obj["length"] = newNumber().SetInt64(int64(len(buf)))
|
||||
return obj, ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["remove"] = builtinFunc{
|
||||
"remove",
|
||||
func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
poss := ArValidToAny(a[0])
|
||||
if typeof(poss) != "number" {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected number, got " + typeof(poss),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
pos := poss.(number)
|
||||
if pos.Denom().Cmp(one.Denom()) != 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "position must be an integer",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
posNum := pos.Num().Int64()
|
||||
buf = append(buf[:posNum], buf[posNum+1:]...)
|
||||
obj.obj["__value__"] = buf
|
||||
obj.obj["length"] = newNumber().SetInt64(int64(len(buf)))
|
||||
return obj, ArErr{}
|
||||
},
|
||||
}
|
||||
|
||||
return obj
|
||||
}
|
||||
@@ -14,7 +14,7 @@ func ArgonString(args ...any) (any, ArErr) {
|
||||
return ArString(""), ArErr{}
|
||||
}
|
||||
args[0] = ArValidToAny(args[0])
|
||||
return ArString(anyToArgon(args[0], true, false, 3, 0, false, 0)), ArErr{}
|
||||
return ArString(anyToArgon(args[0], false, false, 3, 0, false, 0)), ArErr{}
|
||||
}
|
||||
|
||||
func ArgonNumber(args ...any) (any, ArErr) {
|
||||
|
||||
189
src/built-ins.go
189
src/built-ins.go
@@ -5,16 +5,18 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func makeGlobal(allowDocument bool) ArObject {
|
||||
func makeGlobal() ArObject {
|
||||
var vars = anymap{}
|
||||
vars["global"] = vars
|
||||
vars["env"] = env
|
||||
vars["term"] = ArTerm
|
||||
if allowDocument {
|
||||
vars["document"] = ArDocument
|
||||
}
|
||||
vars["js"] = ArJS
|
||||
vars["ArgonVersion"] = ArString(VERSION)
|
||||
vars["number"] = builtinFunc{"number", ArgonNumber}
|
||||
vars["string"] = builtinFunc{"string", ArgonString}
|
||||
vars["socket"] = Map(anymap{
|
||||
"server": builtinFunc{"server", ArSocketServer},
|
||||
"client": builtinFunc{"client", ArSocketClient},
|
||||
})
|
||||
vars["infinity"] = infinity
|
||||
vars["map"] = builtinFunc{"map", func(a ...any) (any, ArErr) {
|
||||
if len(a) == 0 {
|
||||
@@ -51,6 +53,28 @@ func makeGlobal(allowDocument bool) ArObject {
|
||||
}
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot create map from '" + typeof(a[0]) + "'", EXISTS: true}
|
||||
}}
|
||||
vars["hex"] = builtinFunc{"hex", func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
return nil, ArErr{TYPE: "TypeError", message: "expected 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||
}
|
||||
a[0] = ArValidToAny(a[0])
|
||||
switch x := a[0].(type) {
|
||||
case number:
|
||||
if x.Denom().Cmp(one.Denom()) != 0 {
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert non-integer to hex", EXISTS: true}
|
||||
}
|
||||
n := x.Num().Int64()
|
||||
return ArString(fmt.Sprintf("%x", n)), ArErr{}
|
||||
}
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert '" + typeof(a[0]) + "' to hex", EXISTS: true}
|
||||
}}
|
||||
vars["buffer"] = builtinFunc{"buffer", func(a ...any) (any, ArErr) {
|
||||
if len(a) != 0 {
|
||||
return nil, ArErr{TYPE: "TypeError", message: "expected 0 arguments, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||
}
|
||||
return ArBuffer([]byte{}), ArErr{}
|
||||
}}
|
||||
vars["throwError"] = builtinFunc{"throwError", ArThrowError}
|
||||
vars["array"] = builtinFunc{"array", func(a ...any) (any, ArErr) {
|
||||
if len(a) == 0 {
|
||||
return ArArray([]any{}), ArErr{}
|
||||
@@ -154,8 +178,35 @@ func makeGlobal(allowDocument bool) ArObject {
|
||||
vars["cot"] = ArCot
|
||||
vars["arccot"] = ArArccot
|
||||
vars["todeg"] = ArToDeg
|
||||
vars["colour"] = ArColour
|
||||
vars["torad"] = ArToRad
|
||||
vars["abs"] = ArAbs
|
||||
vars["fraction"] = builtinFunc{"fraction", func(a ...any) (any, ArErr) {
|
||||
if len(a) == 0 {
|
||||
return nil, ArErr{TYPE: "fraction", message: "fraction takes 1 argument",
|
||||
EXISTS: true}
|
||||
}
|
||||
switch x := a[0].(type) {
|
||||
case number:
|
||||
return ArString(x.String()), ArErr{}
|
||||
case ArObject:
|
||||
if callable, ok := x.obj["__fraction__"]; ok {
|
||||
resp, err := runCall(
|
||||
call{
|
||||
Callable: callable,
|
||||
Args: []any{},
|
||||
},
|
||||
stack{},
|
||||
0,
|
||||
)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
return resp, ArErr{}
|
||||
}
|
||||
}
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot fraction '" + typeof(a[0]) + "'", EXISTS: true}
|
||||
}}
|
||||
vars["dir"] = builtinFunc{"dir", func(a ...any) (any, ArErr) {
|
||||
if len(a) == 0 {
|
||||
return ArArray([]any{}), ArErr{}
|
||||
@@ -172,25 +223,8 @@ func makeGlobal(allowDocument bool) ArObject {
|
||||
return ArArray([]any{}), ArErr{}
|
||||
}}
|
||||
vars["subprocess"] = builtinFunc{"subprocess", ArSubprocess}
|
||||
vars["object"] = builtinFunc{"object", func(a ...any) (any, ArErr) {
|
||||
if len(a) == 0 {
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot create class from '" + typeof(a[0]) + "'", EXISTS: true}
|
||||
}
|
||||
switch x := a[0].(type) {
|
||||
case ArObject:
|
||||
if typeof(x) == "object" {
|
||||
return x, ArErr{}
|
||||
}
|
||||
newclass := ArObject{obj: anymap{}}
|
||||
for key, val := range x.obj {
|
||||
newclass.obj[key] = val
|
||||
}
|
||||
return newclass, ArErr{}
|
||||
}
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot create class from '" + typeof(a[0]) + "'", EXISTS: true}
|
||||
}}
|
||||
vars["sequence"] = builtinFunc{"sequence", ArSequence}
|
||||
vars["exit"] = builtinFunc{"exit", func(a ...any) (any, ArErr) {
|
||||
vars["|"] = builtinFunc{"exit", func(a ...any) (any, ArErr) {
|
||||
if len(a) == 0 {
|
||||
os.Exit(0)
|
||||
}
|
||||
@@ -201,29 +235,6 @@ func makeGlobal(allowDocument bool) ArObject {
|
||||
os.Exit(0)
|
||||
return nil, ArErr{}
|
||||
}}
|
||||
vars["error"] = builtinFunc{"error", func(a ...any) (any, ArErr) {
|
||||
if len(a) < 1 || len(a) > 2 {
|
||||
return nil, ArErr{TYPE: "error", message: "error takes 1 or 2 arguments, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||
}
|
||||
if len(a) == 1 {
|
||||
a[0] = ArValidToAny(a[0])
|
||||
switch x := a[0].(type) {
|
||||
case string:
|
||||
return nil, ArErr{TYPE: "Error", message: x, EXISTS: true}
|
||||
}
|
||||
} else {
|
||||
a[0] = ArValidToAny(a[0])
|
||||
a[1] = ArValidToAny(a[1])
|
||||
switch x := a[0].(type) {
|
||||
case string:
|
||||
switch y := a[1].(type) {
|
||||
case string:
|
||||
return nil, ArErr{TYPE: x, message: y, EXISTS: true}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot create error from '" + typeof(a[0]) + "'", EXISTS: true}
|
||||
}}
|
||||
vars["chr"] = builtinFunc{"chr", func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
return nil, ArErr{TYPE: "chr", message: "chr takes 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||
@@ -234,5 +245,91 @@ func makeGlobal(allowDocument bool) ArObject {
|
||||
}
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert '" + typeof(a[0]) + "' to string", EXISTS: true}
|
||||
}}
|
||||
vars["ord"] = builtinFunc{"ord", func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
return nil, ArErr{TYPE: "ord", message: "ord takes 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||
}
|
||||
a[0] = ArValidToAny(a[0])
|
||||
switch x := a[0].(type) {
|
||||
case string:
|
||||
if len(x) != 1 {
|
||||
return nil, ArErr{TYPE: "ord", message: "ord takes a string with only one character, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||
}
|
||||
return floor(newNumber().SetInt64(int64([]rune(x)[0]))), ArErr{}
|
||||
}
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert '" + typeof(a[0]) + "' to string", EXISTS: true}
|
||||
}}
|
||||
vars["max"] = builtinFunc{"max", func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
return nil, ArErr{TYPE: "runtime Error", message: "max takes 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||
}
|
||||
a[0] = ArValidToAny(a[0])
|
||||
switch x := a[0].(type) {
|
||||
case []any:
|
||||
if len(x) == 0 {
|
||||
return nil, ArErr{TYPE: "runtime Error", message: "max takes a non-empty array", EXISTS: true}
|
||||
}
|
||||
var max number
|
||||
for i, v := range x {
|
||||
switch m := v.(type) {
|
||||
case number:
|
||||
if i == 0 {
|
||||
max = m
|
||||
} else {
|
||||
if m.Cmp(max) == 1 {
|
||||
max = m
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return max, ArErr{}
|
||||
}
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot get max of type '" + typeof(a[0]) + "'", EXISTS: true}
|
||||
}}
|
||||
vars["min"] = builtinFunc{"min", func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
return nil, ArErr{TYPE: "runtime Error", message: "max takes 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||
}
|
||||
a[0] = ArValidToAny(a[0])
|
||||
switch x := a[0].(type) {
|
||||
case []any:
|
||||
if len(x) == 0 {
|
||||
return nil, ArErr{TYPE: "runtime Error", message: "max takes a non-empty array", EXISTS: true}
|
||||
}
|
||||
var max number
|
||||
for i, v := range x {
|
||||
switch m := v.(type) {
|
||||
case number:
|
||||
if i == 0 {
|
||||
max = m
|
||||
} else {
|
||||
if m.Cmp(max) == -1 {
|
||||
max = m
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return max, ArErr{}
|
||||
}
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot get max of type '" + typeof(a[0]) + "'", EXISTS: true}
|
||||
}}
|
||||
vars["path"] = ArPath
|
||||
vars["typeof"] = builtinFunc{"typeof", func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
return nil, ArErr{TYPE: "typeof", message: "typeof takes 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||
}
|
||||
return ArString(typeof(a[0])), ArErr{}
|
||||
}}
|
||||
vars["sha256"] = builtinFunc{"sha256", func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
return nil, ArErr{TYPE: "sha256", message: "sha256 takes 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||
}
|
||||
a[0] = ArValidToAny(a[0])
|
||||
switch x := a[0].(type) {
|
||||
case string:
|
||||
return ArString(sha256Hash(x)), ArErr{}
|
||||
}
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot hash type '" + typeof(a[0]) + "'", EXISTS: true}
|
||||
}}
|
||||
return Map(vars)
|
||||
}
|
||||
|
||||
66
src/call.go
66
src/call.go
@@ -8,11 +8,11 @@ import (
|
||||
var callCompile = makeRegex("( *)(.|\n)+\\((.|\n)*\\)( *)")
|
||||
|
||||
type call struct {
|
||||
callable any
|
||||
args []any
|
||||
code string
|
||||
line int
|
||||
path string
|
||||
Callable any
|
||||
Args []any
|
||||
Code string
|
||||
Line int
|
||||
Path string
|
||||
}
|
||||
|
||||
type Callable struct {
|
||||
@@ -32,59 +32,60 @@ func parseCall(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, bool,
|
||||
trim := strings.TrimSpace(code.code)
|
||||
trim = trim[:len(trim)-1]
|
||||
splitby := strings.Split(trim, "(")
|
||||
|
||||
var works bool
|
||||
var callable any
|
||||
var arguments []any
|
||||
for i := 1; i < len(splitby); i++ {
|
||||
name := strings.Join(splitby[0:i], "(")
|
||||
argstr := strings.Join(splitby[i:], "(")
|
||||
args, success, argserr := getValuesFromLetter(argstr, ",", index, codelines, false)
|
||||
arguments = args
|
||||
if !success {
|
||||
if i == len(splitby)-1 {
|
||||
return nil, false, argserr, 1
|
||||
}
|
||||
continue
|
||||
}
|
||||
resp, worked, _, _ := translateVal(UNPARSEcode{code: name, realcode: code.realcode, line: index + 1, path: code.path}, index, codelines, 0)
|
||||
resp, worked, err, linecount := translateVal(UNPARSEcode{code: name, realcode: code.realcode, line: index + 1, path: code.path}, index, codelines, 0)
|
||||
if !worked {
|
||||
if i == len(splitby)-1 {
|
||||
return nil, false, ArErr{"Syntax Error", "invalid callable", code.line, code.path, code.realcode, true}, 1
|
||||
return nil, false, err, 1
|
||||
}
|
||||
continue
|
||||
}
|
||||
works = true
|
||||
callable = resp
|
||||
break
|
||||
return call{Callable: resp, Args: args, Line: code.line, Code: code.realcode, Path: code.path}, true, ArErr{}, linecount
|
||||
}
|
||||
if !works {
|
||||
return nil, false, ArErr{"Syntax Error", "invalid call", code.line, code.path, code.realcode, true}, 1
|
||||
}
|
||||
return call{callable: callable, args: arguments, line: code.line, code: code.realcode, path: code.path}, true, ArErr{}, 1
|
||||
}
|
||||
|
||||
func runCall(c call, stack stack, stacklevel int) (any, ArErr) {
|
||||
var callable any
|
||||
switch x := c.callable.(type) {
|
||||
var callable any = c.Callable
|
||||
switch x := c.Callable.(type) {
|
||||
case builtinFunc:
|
||||
callable = x
|
||||
case Callable:
|
||||
callable = x
|
||||
default:
|
||||
callable_, err := runVal(c.callable, stack, stacklevel+1)
|
||||
callable_, err := runVal(c.Callable, stack, stacklevel+1)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
switch x := callable_.(type) {
|
||||
case ArObject:
|
||||
callable_ = x.obj["__call__"]
|
||||
}
|
||||
callable_, err := mapGet(ArMapGet{
|
||||
x,
|
||||
[]any{"__call__"},
|
||||
true,
|
||||
c.Line,
|
||||
c.Code,
|
||||
c.Path,
|
||||
}, stack, stacklevel+1)
|
||||
if !err.EXISTS {
|
||||
callable = callable_
|
||||
}
|
||||
default:
|
||||
callable = callable_
|
||||
}
|
||||
}
|
||||
args := []any{}
|
||||
level := append(stack, newscope())
|
||||
for _, arg := range c.args {
|
||||
for _, arg := range c.Args {
|
||||
resp, err := runVal(arg, level, stacklevel+1)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
@@ -93,35 +94,38 @@ func runCall(c call, stack stack, stacklevel int) (any, ArErr) {
|
||||
}
|
||||
switch x := callable.(type) {
|
||||
case builtinFunc:
|
||||
debugPrintln(x.name, args)
|
||||
resp, err := x.FUNC(args...)
|
||||
resp = AnyToArValid(resp)
|
||||
if err.EXISTS {
|
||||
if err.line == 0 {
|
||||
err.line = c.line
|
||||
err.line = c.Line
|
||||
}
|
||||
if err.path == "" {
|
||||
err.path = c.path
|
||||
err.path = c.Path
|
||||
}
|
||||
if err.code == "" {
|
||||
err.code = c.code
|
||||
err.code = c.Code
|
||||
}
|
||||
}
|
||||
return resp, err
|
||||
case Callable:
|
||||
debugPrintln(x.name, args)
|
||||
if len(x.params) != len(args) {
|
||||
return nil, ArErr{"Runtime Error", "expected " + fmt.Sprint(len(x.params)) + " arguments, got " + fmt.Sprint(len(args)), c.line, c.path, c.code, true}
|
||||
return nil, ArErr{"Runtime Error", "expected " + fmt.Sprint(len(x.params)) + " arguments, got " + fmt.Sprint(len(args)), c.Line, c.Path, c.Code, true}
|
||||
}
|
||||
l := anymap{}
|
||||
for i, param := range x.params {
|
||||
l[param] = args[i]
|
||||
}
|
||||
resp, err := runVal(x.run, append(x.stack, Map(l)), stacklevel+1)
|
||||
return ThrowOnNonLoop(openReturn(resp), err)
|
||||
return openReturn(resp), err
|
||||
}
|
||||
return nil, ArErr{"Runtime Error", "type '" + typeof(callable) + "' is not callable", c.line, c.path, c.code, true}
|
||||
return nil, ArErr{"Runtime Error", "type '" + typeof(callable) + "' is not callable", c.Line, c.Path, c.Code, true}
|
||||
}
|
||||
|
||||
func builtinCall(callable any, args []any) (any, ArErr) {
|
||||
debugPrintln(callable, args)
|
||||
|
||||
switch x := callable.(type) {
|
||||
case builtinFunc:
|
||||
@@ -137,7 +141,7 @@ func builtinCall(callable any, args []any) (any, ArErr) {
|
||||
level.obj[param] = args[i]
|
||||
}
|
||||
resp, err := runVal(x.run, append(x.stack, level), 0)
|
||||
return ThrowOnNonLoop(openReturn(resp), err)
|
||||
return openReturn(resp), err
|
||||
}
|
||||
return nil, ArErr{TYPE: "Runtime Error", message: "type '" + typeof(callable) + "' is not callable", EXISTS: true}
|
||||
}
|
||||
|
||||
96
src/colour.go
Normal file
96
src/colour.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/jwalton/go-supportscolor"
|
||||
)
|
||||
|
||||
var ArColour = Map(
|
||||
anymap{
|
||||
"set": builtinFunc{"set", func(a ...any) (any, ArErr) {
|
||||
if len(a) != 2 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "set() takes exactly 2 argument (" + fmt.Sprint(len(a)) + " given)",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
var c *color.Color
|
||||
var s string
|
||||
if x, ok := a[0].(number); ok {
|
||||
c = color.Set(color.Attribute(x.Num().Int64()))
|
||||
} else {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "set() argument 1 must be an number, not " + typeof(a[0]),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if typeof(a[1]) == "string" {
|
||||
s = ArValidToAny(a[1]).(string)
|
||||
} else {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "set() argument 2 must be a string, not " + typeof(a[1]),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if supportscolor.Stdout().SupportsColor {
|
||||
return c.Sprint(s), ArErr{}
|
||||
} else {
|
||||
return s, ArErr{}
|
||||
}
|
||||
}},
|
||||
"bg": Map(
|
||||
anymap{
|
||||
"black": newNumber().SetInt64(int64(color.BgBlack)),
|
||||
"red": newNumber().SetInt64(int64(color.BgRed)),
|
||||
"green": newNumber().SetInt64(int64(color.BgGreen)),
|
||||
"yellow": newNumber().SetInt64(int64(color.BgYellow)),
|
||||
"blue": newNumber().SetInt64(int64(color.BgBlue)),
|
||||
"magenta": newNumber().SetInt64(int64(color.BgMagenta)),
|
||||
"cyan": newNumber().SetInt64(int64(color.BgCyan)),
|
||||
"white": newNumber().SetInt64(int64(color.BgWhite)),
|
||||
"hiBlack": newNumber().SetInt64(int64(color.BgHiBlack)),
|
||||
"hiRed": newNumber().SetInt64(int64(color.BgHiRed)),
|
||||
"hiGreen": newNumber().SetInt64(int64(color.BgHiGreen)),
|
||||
"hiYellow": newNumber().SetInt64(int64(color.BgHiYellow)),
|
||||
"hiBlue": newNumber().SetInt64(int64(color.BgHiBlue)),
|
||||
"hiMagenta": newNumber().SetInt64(int64(color.BgHiMagenta)),
|
||||
"hiCyan": newNumber().SetInt64(int64(color.BgHiCyan)),
|
||||
"hiWhite": newNumber().SetInt64(int64(color.BgHiWhite)),
|
||||
},
|
||||
),
|
||||
"fg": Map(
|
||||
anymap{
|
||||
"black": newNumber().SetInt64(int64(color.FgBlack)),
|
||||
"red": newNumber().SetInt64(int64(color.FgRed)),
|
||||
"green": newNumber().SetInt64(int64(color.FgGreen)),
|
||||
"yellow": newNumber().SetInt64(int64(color.FgYellow)),
|
||||
"blue": newNumber().SetInt64(int64(color.FgBlue)),
|
||||
"magenta": newNumber().SetInt64(int64(color.FgMagenta)),
|
||||
"cyan": newNumber().SetInt64(int64(color.FgCyan)),
|
||||
"white": newNumber().SetInt64(int64(color.FgWhite)),
|
||||
"hiBlack": newNumber().SetInt64(int64(color.FgHiBlack)),
|
||||
"hiRed": newNumber().SetInt64(int64(color.FgHiRed)),
|
||||
"hiGreen": newNumber().SetInt64(int64(color.FgHiGreen)),
|
||||
"hiYellow": newNumber().SetInt64(int64(color.FgHiYellow)),
|
||||
"hiBlue": newNumber().SetInt64(int64(color.FgHiBlue)),
|
||||
"hiMagenta": newNumber().SetInt64(int64(color.FgHiMagenta)),
|
||||
"hiCyan": newNumber().SetInt64(int64(color.FgHiCyan)),
|
||||
"hiWhite": newNumber().SetInt64(int64(color.FgHiWhite)),
|
||||
},
|
||||
),
|
||||
"reset": newNumber().SetInt64(int64(color.Reset)),
|
||||
"bold": newNumber().SetInt64(int64(color.Bold)),
|
||||
"faint": newNumber().SetInt64(int64(color.Faint)),
|
||||
"italic": newNumber().SetInt64(int64(color.Italic)),
|
||||
"underline": newNumber().SetInt64(int64(color.Underline)),
|
||||
"blinkSlow": newNumber().SetInt64(int64(color.BlinkSlow)),
|
||||
"blinkRapid": newNumber().SetInt64(int64(color.BlinkRapid)),
|
||||
"reverseVideo": newNumber().SetInt64(int64(color.ReverseVideo)),
|
||||
"concealed": newNumber().SetInt64(int64(color.Concealed)),
|
||||
"crossedOut": newNumber().SetInt64(int64(color.CrossedOut)),
|
||||
})
|
||||
@@ -24,7 +24,7 @@ func parseComment(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, bo
|
||||
if isBlank(UNPARSEcode{code: joined, realcode: code.realcode, line: code.line, path: code.path}) {
|
||||
return nil, true, ArErr{}, step
|
||||
}
|
||||
resp, worked, _, s := translateVal(UNPARSEcode{code: joined, realcode: code.realcode, line: code.line, path: code.path}, index, codelines, 2)
|
||||
resp, worked, _, s := translateVal(UNPARSEcode{code: joined, realcode: code.realcode, line: code.line, path: code.path}, index, codelines, 3)
|
||||
step += s - 1
|
||||
if worked {
|
||||
return resp, true, ArErr{}, step
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
var websiteLang = "https://argon.wbell.dev/"
|
||||
var website = "https://argon.wbell.dev/"
|
||||
var docs = "https://argon.wbell.dev/docs/"
|
||||
var mainrepo = "https://github.com/Open-Argon/argon-v3"
|
||||
var mainissuesPage = "https://github.com/Open-Argon/argon-v3/issues"
|
||||
var fork = true
|
||||
var forkrepo = "https://github.com/Open-Argon/argon-v3.wasm"
|
||||
var forkissuesPage = "https://github.com/Open-Argon/argon-v3.wasm/issues"
|
||||
var fork = false
|
||||
var forkrepo = ""
|
||||
var forkissuesPage = ""
|
||||
|
||||
43
src/debug.go
Normal file
43
src/debug.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var debug = os.Getenv("__ARGON_DEBUG__") == "true"
|
||||
|
||||
var __debugPrints = [][]any{}
|
||||
var __debugPrintsLock = sync.RWMutex{}
|
||||
|
||||
func debugInit() {
|
||||
if debug {
|
||||
fmt.Println("In debug mode...")
|
||||
go func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
fmt.Println("debugPrintln: panic:", r)
|
||||
}
|
||||
}()
|
||||
for {
|
||||
__debugPrintsLock.RLock()
|
||||
for _, v := range __debugPrints {
|
||||
fmt.Println(v...)
|
||||
}
|
||||
__debugPrintsLock.RUnlock()
|
||||
__debugPrintsLock.Lock()
|
||||
__debugPrints = [][]any{}
|
||||
__debugPrintsLock.Unlock()
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func debugPrintln(a ...any) {
|
||||
if debug {
|
||||
__debugPrintsLock.Lock()
|
||||
__debugPrints = append(__debugPrints, a)
|
||||
__debugPrintsLock.Unlock()
|
||||
}
|
||||
}
|
||||
213
src/document.go
213
src/document.go
@@ -1,213 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"syscall/js"
|
||||
)
|
||||
|
||||
func windowElement(element js.Value) ArObject {
|
||||
return ArObject{
|
||||
obj: anymap{
|
||||
"innerHTML": builtinFunc{"innerHTML", func(args ...any) (any, ArErr) {
|
||||
if len(args) > 0 {
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{"Argument Error", "innerHTML only accepts strings", 0, "", "", true}
|
||||
}
|
||||
element.Set("innerHTML", args[0].(string))
|
||||
}
|
||||
return element.Get("innerHTML").String(), ArErr{}
|
||||
}},
|
||||
"innerText": builtinFunc{"innerText", func(args ...any) (any, ArErr) {
|
||||
if len(args) > 0 {
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{"Argument Error", "innerText only accepts strings", 0, "", "", true}
|
||||
}
|
||||
element.Set("innerText", args[0].(string))
|
||||
}
|
||||
return element.Get("innerText").String(), ArErr{}
|
||||
}},
|
||||
"addEventListener": builtinFunc{"addEventListener", func(args ...any) (any, ArErr) {
|
||||
if len(args) < 2 {
|
||||
return nil, ArErr{"Argument Error", "Not enough arguments for addEventListener", 0, "", "", true}
|
||||
}
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{"Argument Error", "addEventListener's first argument must be a string", 0, "", "", true}
|
||||
}
|
||||
event := args[0].(string)
|
||||
if typeof(args[1]) != "function" {
|
||||
return nil, ArErr{"Argument Error", "addEventListener's second argument must be a function", 0, "", "", true}
|
||||
}
|
||||
callable := args[1]
|
||||
element.Call("addEventListener", event, js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||
runCall(call{
|
||||
callable: callable,
|
||||
args: []any{},
|
||||
}, stack{}, 0)
|
||||
return nil
|
||||
}))
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"removeEventListener": builtinFunc{"removeEventListener", func(args ...any) (any, ArErr) {
|
||||
if len(args) < 2 {
|
||||
return nil, ArErr{"Argument Error", "Not enough arguments for removeEventListener", 0, "", "", true}
|
||||
}
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{"Argument Error", "removeEventListener's first argument must be a string", 0, "", "", true}
|
||||
}
|
||||
event := args[0].(string)
|
||||
if typeof(args[1]) != "function" {
|
||||
return nil, ArErr{"Argument Error", "removeEventListener's second argument must be a function", 0, "", "", true}
|
||||
}
|
||||
callable := args[1]
|
||||
element.Call("removeEventListener", event, js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||
runCall(call{
|
||||
callable: callable,
|
||||
args: []any{},
|
||||
}, stack{}, 0)
|
||||
return nil
|
||||
}))
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"appendChild": builtinFunc{"appendChild", func(args ...any) (any, ArErr) {
|
||||
if len(args) < 1 {
|
||||
return nil, ArErr{"Argument Error", "Not enough arguments for appendChild", 0, "", "", true}
|
||||
}
|
||||
if typeof(args[0]) != "map" {
|
||||
return nil, ArErr{"Argument Error", "appendChild's first argument must be a map", 0, "", "", true}
|
||||
}
|
||||
child := args[0].(anymap)
|
||||
if child["__TYPE__"] != "windowElement" {
|
||||
return nil, ArErr{"Argument Error", "appendChild's first argument must be an element", 0, "", "", true}
|
||||
}
|
||||
element.Call("appendChild", child["__element__"])
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"removeChild": builtinFunc{"removeChild", func(args ...any) (any, ArErr) {
|
||||
if len(args) < 1 {
|
||||
return nil, ArErr{"Argument Error", "Not enough arguments for removeChild", 0, "", "", true}
|
||||
}
|
||||
if typeof(args[0]) != "map" {
|
||||
return nil, ArErr{"Argument Error", "removeChild's first argument must be a map", 0, "", "", true}
|
||||
}
|
||||
child := args[0].(anymap)
|
||||
if child["__TYPE__"] != "windowElement" {
|
||||
return nil, ArErr{"Argument Error", "removeChild's first argument must be an element", 0, "", "", true}
|
||||
}
|
||||
element.Call("removeChild", child["__element__"])
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"setAttribute": builtinFunc{"setAttribute", func(args ...any) (any, ArErr) {
|
||||
if len(args) < 2 {
|
||||
return nil, ArErr{"Argument Error", "Not enough arguments for setAttribute", 0, "", "", true}
|
||||
}
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{"Argument Error", "setAttribute's first argument must be a string", 0, "", "", true}
|
||||
}
|
||||
element.Call("setAttribute", args[0].(string), anyToArgon(args[1], false, false, 3, 0, false, 0))
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"__element__": element,
|
||||
"__TYPE__": "windowElement",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
var ArDocument = Map(
|
||||
anymap{
|
||||
"body": builtinFunc{"getElementById", func(args ...any) (any, ArErr) {
|
||||
return windowElement(js.Global().Get("document").Get("body")), ArErr{}
|
||||
}},
|
||||
"head": builtinFunc{"getElementById", func(args ...any) (any, ArErr) {
|
||||
return windowElement(js.Global().Get("document").Get("head")), ArErr{}
|
||||
}},
|
||||
"getElementById": builtinFunc{"getElementById", func(args ...any) (any, ArErr) {
|
||||
if len(args) < 1 {
|
||||
return nil, ArErr{"Argument Error", "Not enough arguments for getElementById", 0, "", "", true}
|
||||
}
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{"Argument Error", "getElementById's first argument must be a string", 0, "", "", true}
|
||||
}
|
||||
id := args[0].(string)
|
||||
result := js.Global().Get("document").Call("getElementById", id)
|
||||
if js.Null().Equal(result) {
|
||||
return nil, ArErr{}
|
||||
}
|
||||
return windowElement(result), ArErr{}
|
||||
}},
|
||||
"createElement": builtinFunc{"createElement", func(args ...any) (any, ArErr) {
|
||||
if len(args) < 1 {
|
||||
return nil, ArErr{"Argument Error", "Not enough arguments for createElement", 0, "", "", true}
|
||||
}
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{"Argument Error", "createElement's first argument must be a string", 0, "", "", true}
|
||||
}
|
||||
tag := args[0].(string)
|
||||
return windowElement(js.Global().Get("document").Call("createElement", tag)), ArErr{}
|
||||
}},
|
||||
"createTextNode": builtinFunc{"createTextNode", func(args ...any) (any, ArErr) {
|
||||
if len(args) < 1 {
|
||||
return nil, ArErr{"Argument Error", "Not enough arguments for createTextNode", 0, "", "", true}
|
||||
}
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{"Argument Error", "createTextNode's first argument must be a string", 0, "", "", true}
|
||||
}
|
||||
text := args[0].(string)
|
||||
return windowElement(js.Global().Get("document").Call("createTextNode", text)), ArErr{}
|
||||
}},
|
||||
"createComment": builtinFunc{"createComment", func(args ...any) (any, ArErr) {
|
||||
if len(args) < 1 {
|
||||
return nil, ArErr{"Argument Error", "Not enough arguments for createComment", 0, "", "", true}
|
||||
}
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{"Argument Error", "createComment's first argument must be a string", 0, "", "", true}
|
||||
}
|
||||
text := args[0].(string)
|
||||
return windowElement(js.Global().Get("document").Call("createComment", text)), ArErr{}
|
||||
}},
|
||||
"createDocumentFragment": builtinFunc{"createDocumentFragment", func(args ...any) (any, ArErr) {
|
||||
return windowElement(js.Global().Get("document").Call("createDocumentFragment")), ArErr{}
|
||||
}},
|
||||
"addEventListener": builtinFunc{"addEventListener", func(args ...any) (any, ArErr) {
|
||||
if len(args) < 2 {
|
||||
return nil, ArErr{"Argument Error", "Not enough arguments for addEventListener", 0, "", "", true}
|
||||
}
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{"Argument Error", "addEventListener's first argument must be a string", 0, "", "", true}
|
||||
}
|
||||
event := args[0].(string)
|
||||
if typeof(args[1]) != "function" {
|
||||
return nil, ArErr{"Argument Error", "addEventListener's second argument must be a function", 0, "", "", true}
|
||||
}
|
||||
callable := args[1]
|
||||
js.Global().Get("document").Call("addEventListener", event, js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||
runCall(call{
|
||||
callable: callable,
|
||||
args: []any{},
|
||||
}, stack{}, 0)
|
||||
return nil
|
||||
}))
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"removeEventListener": builtinFunc{"removeEventListener", func(args ...any) (any, ArErr) {
|
||||
if len(args) < 2 {
|
||||
return nil, ArErr{"Argument Error", "Not enough arguments for removeEventListener", 0, "", "", true}
|
||||
}
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{"Argument Error", "removeEventListener's first argument must be a string", 0, "", "", true}
|
||||
}
|
||||
event := args[0].(string)
|
||||
if typeof(args[1]) != "function" {
|
||||
return nil, ArErr{"Argument Error", "removeEventListener's second argument must be a function", 0, "", "", true}
|
||||
}
|
||||
callable := args[1]
|
||||
js.Global().Get("document").Call("removeEventListener", event, js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||
runCall(call{
|
||||
callable: callable,
|
||||
args: []any{},
|
||||
}, stack{}, 0)
|
||||
return nil
|
||||
}))
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"__TYPE__": "document",
|
||||
},
|
||||
)
|
||||
@@ -35,10 +35,10 @@ func parseDoWrap(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, boo
|
||||
break
|
||||
}
|
||||
if indent != setindent {
|
||||
return nil, false, ArErr{"Syntax Error", "invalid indent", code.line, code.path, code.realcode, true}, 1
|
||||
return nil, false, ArErr{"Syntax Error", "invalid indent", i, code.path, codelines[i].code, true}, 1
|
||||
}
|
||||
|
||||
val, _, err, step := translateVal(codelines[i], i, codelines, 2)
|
||||
val, _, err, step := translateVal(codelines[i], i, codelines, 3)
|
||||
i += step
|
||||
if err.EXISTS {
|
||||
return nil, false, err, i - index
|
||||
@@ -56,9 +56,7 @@ func runDoWrap(d dowrap, stack stack, stacklevel int) (any, ArErr) {
|
||||
return nil, err
|
||||
}
|
||||
switch x := val.(type) {
|
||||
case Return:
|
||||
return x, ArErr{}
|
||||
case Break:
|
||||
case Return, Break, Continue:
|
||||
return x, ArErr{}
|
||||
}
|
||||
}
|
||||
|
||||
29
src/env.go
Normal file
29
src/env.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
// get the environment variables
|
||||
func getEnv() ArObject {
|
||||
env := make(anymap)
|
||||
for _, e := range os.Environ() {
|
||||
pair := strings.Split(e, "=")
|
||||
env[pair[0]] = ArString(pair[1])
|
||||
}
|
||||
err := godotenv.Load(".env")
|
||||
if err == nil {
|
||||
values, err := godotenv.Read()
|
||||
if err == nil {
|
||||
for k, v := range values {
|
||||
env[k] = ArString(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
return Map(env)
|
||||
}
|
||||
|
||||
var env = getEnv()
|
||||
33
src/error.go
33
src/error.go
@@ -2,8 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/jwalton/go-supportscolor"
|
||||
)
|
||||
|
||||
type ArErr struct {
|
||||
@@ -15,15 +13,38 @@ type ArErr struct {
|
||||
EXISTS bool
|
||||
}
|
||||
|
||||
func ArThrowError(a ...any) (any, ArErr) {
|
||||
if len(a) != 2 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "throwError takes 2 arguments, " + fmt.Sprint(len(a)) + " given",
|
||||
EXISTS: true,
|
||||
}
|
||||
} else if typeof(a[0]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "throwError type must be a string",
|
||||
EXISTS: true,
|
||||
}
|
||||
} else if typeof(a[1]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "throwError message must be a string",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return nil, ArErr{
|
||||
TYPE: ArValidToAny(a[0]).(string),
|
||||
message: ArValidToAny(a[1]).(string),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
|
||||
func panicErr(err ArErr) {
|
||||
if err.code != "" && err.line != 0 && err.path != "" {
|
||||
fmt.Println(" File:", err.path+":"+fmt.Sprint(err.line))
|
||||
fmt.Println(" " + err.code)
|
||||
fmt.Println()
|
||||
}
|
||||
if supportscolor.Stdout().SupportsColor {
|
||||
fmt.Printf("\x1b[%dm%s\x1b[0m", 91, fmt.Sprint(err.TYPE, ": ", err.message, "\n"))
|
||||
} else {
|
||||
fmt.Println(fmt.Sprint(err.TYPE, ": ", err.message))
|
||||
}
|
||||
}
|
||||
|
||||
126
src/file.go
126
src/file.go
@@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
)
|
||||
|
||||
var ArFile = Map(anymap{
|
||||
@@ -21,6 +23,15 @@ func readtext(file *os.File) (string, error) {
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
||||
func readbinary(file *os.File) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
_, err := io.Copy(&buf, file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ArRead(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "read takes 1 argument, got " + fmt.Sprint(len(args)), EXISTS: true}
|
||||
@@ -34,6 +45,18 @@ func ArRead(args ...any) (any, ArErr) {
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
|
||||
fileInfo, err := os.Stat(filename)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "File does not exist: " + filename, EXISTS: true}
|
||||
} else {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
} else if fileInfo.Mode().IsDir() {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "path goes to a directory, not a file: " + filename, EXISTS: true}
|
||||
}
|
||||
|
||||
return Map(anymap{
|
||||
"text": builtinFunc{"text", func(...any) (any, ArErr) {
|
||||
text, err := readtext(file)
|
||||
@@ -49,6 +72,77 @@ func ArRead(args ...any) (any, ArErr) {
|
||||
}
|
||||
return jsonparse(text), ArErr{}
|
||||
}},
|
||||
"contentType": builtinFunc{"contentType", func(...any) (any, ArErr) {
|
||||
file.Seek(0, io.SeekStart)
|
||||
mimetype, err := mimetype.DetectReader(file)
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return mimetype.String(), ArErr{}
|
||||
}},
|
||||
"buffer": builtinFunc{"buffer", func(args ...any) (any, ArErr) {
|
||||
if len(args) > 1 {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "buffer takes 0 or 1 argument, got " + fmt.Sprint(len(args)), EXISTS: true}
|
||||
}
|
||||
if len(args) == 1 {
|
||||
if typeof(args[0]) != "number" {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "buffer takes a number not type '" + typeof(args[0]) + "'", EXISTS: true}
|
||||
}
|
||||
size := args[0].(number)
|
||||
if size.Denom().Int64() != 1 {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "buffer takes an integer not type '" + typeof(args[0]) + "'", EXISTS: true}
|
||||
}
|
||||
buf := make([]byte, size.Num().Int64())
|
||||
n, err := file.Read(buf)
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return ArBuffer(buf[:n]), ArErr{}
|
||||
}
|
||||
bytes, err := readbinary(file)
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return ArBuffer(bytes), ArErr{}
|
||||
}},
|
||||
"seek": builtinFunc{"seek", func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "seek takes 1 argument, got " + fmt.Sprint(len(args)), EXISTS: true}
|
||||
}
|
||||
if typeof(args[0]) != "number" {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "seek takes a number not type '" + typeof(args[0]) + "'", EXISTS: true}
|
||||
}
|
||||
offset := args[0].(number)
|
||||
if offset.Denom().Int64() != 1 {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "seek takes an integer not type '" + typeof(args[0]) + "'", EXISTS: true}
|
||||
}
|
||||
_, err := file.Seek(offset.Num().Int64(), io.SeekStart)
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"size": builtinFunc{"size", func(...any) (any, ArErr) {
|
||||
info, err := file.Stat()
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return newNumber().SetInt64(info.Size()), ArErr{}
|
||||
}},
|
||||
"ModTime": builtinFunc{"ModTime", func(...any) (any, ArErr) {
|
||||
info, err := file.Stat()
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return ArTimeClass(info.ModTime()), ArErr{}
|
||||
}},
|
||||
"close": builtinFunc{"close", func(...any) (any, ArErr) {
|
||||
err := file.Close()
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
}), ArErr{}
|
||||
}
|
||||
|
||||
@@ -73,7 +167,25 @@ func ArWrite(args ...any) (any, ArErr) {
|
||||
if typeof(args[0]) != "string" {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "text takes a string not type '" + typeof(args[0]) + "'", EXISTS: true}
|
||||
}
|
||||
file.Write([]byte(args[0].(string)))
|
||||
args[0] = ArValidToAny(args[0])
|
||||
_, err = file.Write([]byte(args[0].(string)))
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"buffer": builtinFunc{"buffer", func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "buffer takes 1 argument, got " + fmt.Sprint(len(args)), EXISTS: true}
|
||||
}
|
||||
if typeof(args[0]) != "buffer" {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "buffer takes a buffer not type '" + typeof(args[0]) + "'", EXISTS: true}
|
||||
}
|
||||
args[0] = ArValidToAny(args[0])
|
||||
_, err = file.Write(args[0].([]byte))
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"json": builtinFunc{"json", func(args ...any) (any, ArErr) {
|
||||
@@ -84,7 +196,17 @@ func ArWrite(args ...any) (any, ArErr) {
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
file.Write([]byte(jsonstr))
|
||||
_, err = file.Write([]byte(jsonstr))
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"close": builtinFunc{"close", func(...any) (any, ArErr) {
|
||||
err := file.Close()
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
}), ArErr{}
|
||||
|
||||
@@ -15,10 +15,11 @@ var indexGetCompile = makeRegex(`(.|\n)+\[(.|\n)+\]( *)`)
|
||||
|
||||
type ArMapGet struct {
|
||||
VAL any
|
||||
args []any
|
||||
line int
|
||||
code string
|
||||
path string
|
||||
Args []any
|
||||
IncludeConstuctors bool
|
||||
Line int
|
||||
Code string
|
||||
Path string
|
||||
}
|
||||
|
||||
func mapGet(r ArMapGet, stack stack, stacklevel int) (any, ArErr) {
|
||||
@@ -28,36 +29,33 @@ func mapGet(r ArMapGet, stack stack, stacklevel int) (any, ArErr) {
|
||||
}
|
||||
switch m := resp.(type) {
|
||||
case ArObject:
|
||||
if _, ok := m.obj["__getindex__"]; ok {
|
||||
callable := m.obj["__getindex__"]
|
||||
if r.IncludeConstuctors {
|
||||
if obj, ok := m.obj[r.Args[0]]; ok {
|
||||
return obj, ArErr{}
|
||||
}
|
||||
}
|
||||
if callable, ok := m.obj["__getindex__"]; ok {
|
||||
resp, err := runCall(call{
|
||||
callable: callable,
|
||||
args: r.args,
|
||||
line: r.line,
|
||||
path: r.path,
|
||||
code: r.code,
|
||||
Callable: callable,
|
||||
Args: r.Args,
|
||||
Line: r.Line,
|
||||
Path: r.Path,
|
||||
Code: r.Code,
|
||||
}, stack, stacklevel+1)
|
||||
if !err.EXISTS {
|
||||
return resp, ArErr{}
|
||||
}
|
||||
if len(r.args) == 1 && !isUnhashable(r.args[0]) {
|
||||
if _, ok := m.obj[r.args[0]]; ok {
|
||||
return m.obj[r.args[0]], ArErr{}
|
||||
}
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
}
|
||||
|
||||
key, err := runVal(r.args[0], stack, stacklevel+1)
|
||||
key, err := runVal(r.Args[0], stack, stacklevel+1)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
return nil, ArErr{
|
||||
"TypeError",
|
||||
"cannot read " + anyToArgon(key, true, true, 3, 0, false, 0) + " from type '" + typeof(resp) + "'",
|
||||
r.line,
|
||||
r.path,
|
||||
r.code,
|
||||
r.Line,
|
||||
r.Path,
|
||||
r.Code,
|
||||
true,
|
||||
}
|
||||
}
|
||||
@@ -75,7 +73,7 @@ func mapGetParse(code UNPARSEcode, index int, codelines []UNPARSEcode) (ArMapGet
|
||||
if !worked {
|
||||
return ArMapGet{}, false, err, i
|
||||
}
|
||||
return ArMapGet{resp, []any{key}, code.line, code.realcode, code.path}, true, ArErr{}, 1
|
||||
return ArMapGet{resp, []any{key}, true, code.line, code.realcode, code.path}, true, ArErr{}, 1
|
||||
}
|
||||
|
||||
func isIndexGet(code UNPARSEcode) bool {
|
||||
@@ -113,7 +111,7 @@ func indexGetParse(code UNPARSEcode, index int, codelines []UNPARSEcode) (ArMapG
|
||||
}
|
||||
continue
|
||||
}
|
||||
return ArMapGet{tival, args, code.line, code.realcode, code.path}, true, ArErr{}, 1
|
||||
return ArMapGet{tival, args, false, code.line, code.realcode, code.path}, true, ArErr{}, 1
|
||||
}
|
||||
return ArMapGet{}, false, ArErr{
|
||||
"Syntax Error",
|
||||
|
||||
@@ -50,8 +50,7 @@ func parseIfStatement(code UNPARSEcode, index int, codeline []UNPARSEcode) (ifst
|
||||
},
|
||||
i,
|
||||
codeline,
|
||||
0,
|
||||
)
|
||||
0)
|
||||
if err.EXISTS || !worked {
|
||||
if j == 1 {
|
||||
return ifstatement{}, worked, err, step
|
||||
|
||||
@@ -2,30 +2,26 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var imported = make(map[string]ArObject)
|
||||
var importing = make(map[string]bool)
|
||||
|
||||
const modules_folder = "argon_modules"
|
||||
|
||||
func FileExists(filename string) bool {
|
||||
if _, err := os.Stat(filename); err == nil {
|
||||
if info, err := os.Stat(filename); err == nil && !info.IsDir() {
|
||||
return true
|
||||
|
||||
} else if errors.Is(err, os.ErrNotExist) {
|
||||
return false
|
||||
} else {
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func readFile(path string) []UNPARSEcode {
|
||||
func readFile(path string) ([]UNPARSEcode, error) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return nil
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
@@ -40,19 +36,12 @@ func readFile(path string) []UNPARSEcode {
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
log.Fatal(err)
|
||||
return nil
|
||||
return nil, err
|
||||
}
|
||||
return output
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func importMod(realpath string, origin string, main bool, global ArObject) (ArObject, ArErr) {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "Import Error",
|
||||
message: "importing in WASM is currently not supported",
|
||||
EXISTS: true,
|
||||
}
|
||||
/*
|
||||
extention := filepath.Ext(realpath)
|
||||
path := realpath
|
||||
if extention == "" {
|
||||
@@ -76,18 +65,17 @@ func importMod(realpath string, origin string, main bool, global ArObject) (ArOb
|
||||
}
|
||||
} else {
|
||||
pathsToTest = []string{
|
||||
filepath.Join(origin, realpath, "init.ar"),
|
||||
filepath.Join(origin, path),
|
||||
filepath.Join(origin, "modules", path),
|
||||
filepath.Join(origin, "modules", realpath, "init.ar"),
|
||||
filepath.Join(origin, realpath, "init.ar"),
|
||||
filepath.Join(origin, modules_folder, path),
|
||||
filepath.Join(origin, modules_folder, realpath, "init.ar"),
|
||||
filepath.Join(ex, path),
|
||||
filepath.Join(ex, "modules", realpath, "init.ar"),
|
||||
filepath.Join(ex, "modules", path),
|
||||
filepath.Join(executable, "modules", realpath, "init.ar"),
|
||||
filepath.Join(executable, "modules", path),
|
||||
filepath.Join(ex, modules_folder, path),
|
||||
filepath.Join(ex, modules_folder, realpath, "init.ar"),
|
||||
filepath.Join(executable, modules_folder, path),
|
||||
filepath.Join(executable, modules_folder, realpath, "init.ar"),
|
||||
}
|
||||
}
|
||||
|
||||
var p string
|
||||
var found bool
|
||||
for _, p = range pathsToTest {
|
||||
@@ -98,16 +86,19 @@ func importMod(realpath string, origin string, main bool, global ArObject) (ArOb
|
||||
}
|
||||
|
||||
if !found {
|
||||
return ArObject{}, ArErr{TYPE: "Import Error", message: "File does not exist: " + realpath, EXISTS: true}
|
||||
return ArObject{}, ArErr{TYPE: "Import Error", message: "File does not exist: " + path, EXISTS: true}
|
||||
} else if importing[p] {
|
||||
return ArObject{}, ArErr{TYPE: "Import Error", message: "Circular import: " + realpath, EXISTS: true}
|
||||
return ArObject{}, ArErr{TYPE: "Import Error", message: "Circular import: " + path, EXISTS: true}
|
||||
} else if _, ok := imported[p]; ok {
|
||||
return imported[p], ArErr{}
|
||||
}
|
||||
importing[p] = true
|
||||
codelines := readFile(p)
|
||||
|
||||
codelines, err := readFile(p)
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Import Error", message: "Could not read file: " + path, EXISTS: true}
|
||||
}
|
||||
translated, translationerr := translate(codelines)
|
||||
|
||||
if translationerr.EXISTS {
|
||||
return ArObject{}, translationerr
|
||||
}
|
||||
@@ -119,11 +110,11 @@ func importMod(realpath string, origin string, main bool, global ArObject) (ArOb
|
||||
for _, arg := range withoutarfile {
|
||||
ArgsArArray = append(ArgsArArray, arg)
|
||||
}
|
||||
global := newscope()
|
||||
local := newscope()
|
||||
localvars := Map(anymap{
|
||||
"program": Map(anymap{
|
||||
"args": ArArray(ArgsArArray),
|
||||
"origin": origin,
|
||||
"origin": ArString(origin),
|
||||
"import": builtinFunc{"import", func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{"Import Error", "Invalid number of arguments", 0, realpath, "", true}
|
||||
@@ -131,24 +122,22 @@ func importMod(realpath string, origin string, main bool, global ArObject) (ArOb
|
||||
if _, ok := args[0].(string); !ok {
|
||||
return nil, ArErr{"Import Error", "Invalid argument type", 0, realpath, "", true}
|
||||
}
|
||||
return importMod(args[0].(string), filepath.Dir(p), false)
|
||||
return importMod(args[0].(string), filepath.Dir(filepath.ToSlash(p)), false, global)
|
||||
}},
|
||||
"cwd": ex,
|
||||
"exc": exc,
|
||||
"cwd": ArString(ex),
|
||||
"exc": ArString(exc),
|
||||
"file": Map(anymap{
|
||||
"name": filepath.Base(p),
|
||||
"path": p,
|
||||
"name": ArString(filepath.Base(p)),
|
||||
"path": ArString(p),
|
||||
}),
|
||||
"main": main,
|
||||
"scope": global,
|
||||
}),
|
||||
})
|
||||
_, runimeErr := ThrowOnNonLoop(run(translated, stack{vars, localvars, global}))
|
||||
_, runimeErr := run(translated, stack{global, localvars, local})
|
||||
importing[p] = false
|
||||
if runimeErr.EXISTS {
|
||||
return ArObject{}, runimeErr
|
||||
}
|
||||
imported[p] = global
|
||||
return global, ArErr{}
|
||||
*/
|
||||
imported[p] = local
|
||||
return local, ArErr{}
|
||||
}
|
||||
|
||||
1
src/infinity.go
Normal file
1
src/infinity.go
Normal file
@@ -0,0 +1 @@
|
||||
package main
|
||||
21
src/input.go
21
src/input.go
@@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"syscall/js"
|
||||
|
||||
"golang.org/x/term"
|
||||
)
|
||||
@@ -12,15 +12,12 @@ func input(args ...any) string {
|
||||
output := []any{}
|
||||
for i := 0; i < len(args); i++ {
|
||||
output = append(output, anyToArgon(args[i], false, true, 3, 0, true, 0))
|
||||
if i != len(args)-1 {
|
||||
output = append(output, " ")
|
||||
}
|
||||
}
|
||||
text := fmt.Sprint(output...)
|
||||
fmt.Print(text)
|
||||
inputData := js.Global().Get("getInput").Invoke(fmt.Sprint(output...)).String()
|
||||
fmt.Println(inputData)
|
||||
return (inputData)
|
||||
fmt.Print(output...)
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
scanner.Scan()
|
||||
input := scanner.Text()
|
||||
return input
|
||||
}
|
||||
|
||||
func getPassword(args ...any) (string, error) {
|
||||
@@ -61,3 +58,9 @@ func getPassword(args ...any) (string, error) {
|
||||
fmt.Print("\r")
|
||||
return string(password), nil
|
||||
}
|
||||
|
||||
func pause() {
|
||||
fmt.Print("Press Enter to continue...")
|
||||
term.ReadPassword(int(os.Stdin.Fd()))
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func convertToArgon(obj any) any {
|
||||
}
|
||||
return ArArray(x)
|
||||
case string:
|
||||
return x
|
||||
return ArString(x)
|
||||
case float64:
|
||||
return newNumber().SetFloat64(x)
|
||||
case bool:
|
||||
@@ -46,8 +46,8 @@ func jsonstringify(obj any, level int) (string, error) {
|
||||
output := []string{}
|
||||
obj = ArValidToAny(obj)
|
||||
switch x := obj.(type) {
|
||||
case ArObject:
|
||||
for key, value := range x.obj {
|
||||
case anymap:
|
||||
for key, value := range x {
|
||||
str, err := jsonstringify(value, level+1)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -89,6 +89,7 @@ var ArJSON = Map(anymap{
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{TYPE: "Runtime Error", message: "parse takes a string not a '" + typeof(args[0]) + "'", EXISTS: true}
|
||||
}
|
||||
args[0] = ArValidToAny(args[0])
|
||||
return jsonparse(args[0].(string)), ArErr{}
|
||||
}},
|
||||
"stringify": builtinFunc{"stringify", func(args ...any) (any, ArErr) {
|
||||
@@ -99,6 +100,6 @@ var ArJSON = Map(anymap{
|
||||
if err != nil {
|
||||
return nil, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return str, ArErr{}
|
||||
return ArString(str), ArErr{}
|
||||
}},
|
||||
})
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var returnCompile = makeRegex(`( *)return( +)(.|\n)+`)
|
||||
var returnCompile = makeRegex(`( *)return(( +)(.|\n)+)?`)
|
||||
var breakCompile = makeRegex(`( *)break( *)`)
|
||||
var continueCompile = makeRegex(`( *)continue( *)`)
|
||||
|
||||
@@ -45,12 +45,17 @@ func isContinue(code UNPARSEcode) bool {
|
||||
}
|
||||
|
||||
func parseReturn(code UNPARSEcode, index int, codeline []UNPARSEcode) (CallReturn, bool, ArErr, int) {
|
||||
resp, worked, err, i := translateVal(UNPARSEcode{
|
||||
code: strings.TrimSpace(code.code)[6:],
|
||||
val := strings.TrimSpace(code.code)[6:]
|
||||
var resp any
|
||||
var worked, err, i = true, ArErr{}, 1
|
||||
if val != "" {
|
||||
resp, worked, err, i = translateVal(UNPARSEcode{
|
||||
code: val,
|
||||
realcode: code.realcode,
|
||||
line: code.line,
|
||||
path: code.path,
|
||||
}, index, codeline, 1)
|
||||
}
|
||||
return CallReturn{
|
||||
value: resp,
|
||||
line: code.line,
|
||||
@@ -66,6 +71,7 @@ func runReturn(code CallReturn, stack stack, stacklevel int) (any, ArErr) {
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
v = openReturn(v)
|
||||
val = v
|
||||
}
|
||||
return Return{
|
||||
@@ -76,6 +82,19 @@ func runReturn(code CallReturn, stack stack, stacklevel int) (any, ArErr) {
|
||||
}, ArErr{}
|
||||
}
|
||||
|
||||
func translateThrowOnNonLoop(val any) ArErr {
|
||||
switch x := val.(type) {
|
||||
case Break:
|
||||
return ArErr{"Break Error", "break can only be used in loops", x.line, x.path, x.code, true}
|
||||
case Continue:
|
||||
return ArErr{"Continue Error", "continue can only be used in loops", x.line, x.path, x.code, true}
|
||||
case CallReturn:
|
||||
return ArErr{"Return Error", "return can only be used in do wraps", x.line, x.path, x.code, true}
|
||||
default:
|
||||
return ArErr{}
|
||||
}
|
||||
}
|
||||
|
||||
func openReturn(resp any) any {
|
||||
switch x := resp.(type) {
|
||||
case Return:
|
||||
|
||||
44
src/main.go
44
src/main.go
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"syscall/js"
|
||||
)
|
||||
|
||||
// args without the program path
|
||||
@@ -11,16 +10,29 @@ var Args = os.Args[1:]
|
||||
|
||||
type stack = []ArObject
|
||||
|
||||
const VERSION = "3.0.1"
|
||||
|
||||
// Example struct
|
||||
type Person struct {
|
||||
Name string
|
||||
Age int
|
||||
}
|
||||
|
||||
func newscope() ArObject {
|
||||
return Map(anymap{})
|
||||
}
|
||||
|
||||
func main() {
|
||||
c := make(chan ArObject)
|
||||
debugInit()
|
||||
|
||||
if !debug {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
fmt.Println("There was a fundamental error in argon v3 that caused it to crash.")
|
||||
fmt.Println()
|
||||
fmt.Println("website:", website)
|
||||
fmt.Println("docs:", docs)
|
||||
fmt.Println()
|
||||
if fork {
|
||||
fmt.Println("This is a fork of Open-Argon. Please report this to the fork's maintainer.")
|
||||
fmt.Println("Fork repo:", forkrepo)
|
||||
@@ -37,26 +49,24 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
}
|
||||
initRandom()
|
||||
garbageCollect()
|
||||
obj := js.Global().Get("Object").New()
|
||||
obj.Set("eval", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||
code := ""
|
||||
allowDocument := false
|
||||
if len(args) >= 1 {
|
||||
code = args[0].String()
|
||||
global := makeGlobal()
|
||||
if len(Args) == 0 {
|
||||
shell(global)
|
||||
os.Exit(0)
|
||||
}
|
||||
if len(args) >= 2 {
|
||||
allowDocument = args[1].Bool()
|
||||
ex, e := os.Getwd()
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
val, err := wasmRun(code, allowDocument)
|
||||
_, err := importMod(Args[0], ex, true, global)
|
||||
if err.EXISTS {
|
||||
panicErr(err)
|
||||
return js.Null()
|
||||
os.Exit(1)
|
||||
}
|
||||
if threadCount > 0 {
|
||||
<-threadChan
|
||||
}
|
||||
|
||||
return js.ValueOf(argonToJsValid(val))
|
||||
}))
|
||||
js.Global().Set("Ar", obj)
|
||||
<-c
|
||||
}
|
||||
|
||||
364
src/map.go
364
src/map.go
@@ -6,10 +6,10 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
var mapCompiled = makeRegex(`( *)\{(((( *).+( *):( *).+( *))|(` + spacelessVariable + `))(( *)\,(( *).+( *):( *).+( *))|(` + spacelessVariable + `)))*\}( *)`)
|
||||
var mapCompiled = makeRegex(`( )*{( |\n)*(((.|\n)+)(,(.|\n)+)*)?( |\n)*}( )*`)
|
||||
|
||||
type createMap struct {
|
||||
body anymap
|
||||
body [][2]any
|
||||
code string
|
||||
line int
|
||||
path string
|
||||
@@ -19,16 +19,108 @@ func isMap(code UNPARSEcode) bool {
|
||||
return mapCompiled.MatchString(code.code)
|
||||
}
|
||||
|
||||
func parseMap(code UNPARSEcode) (any, UNPARSEcode) {
|
||||
trimmed := strings.Trim(code.code, " ")
|
||||
trimmed = trimmed[1 : len(trimmed)-1]
|
||||
fmt.Println(trimmed)
|
||||
return nil, UNPARSEcode{}
|
||||
func runCreateMap(m createMap, stack stack, stacklevel int) (any, ArErr) {
|
||||
var body = m.body
|
||||
var newmap = anymap{}
|
||||
for _, pair := range body {
|
||||
key := pair[0]
|
||||
val := pair[1]
|
||||
keyVal, err := runVal(key, stack, stacklevel+1)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
keyVal = ArValidToAny(keyVal)
|
||||
valVal, err := runVal(val, stack, stacklevel+1)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
if isUnhashable(keyVal) {
|
||||
return nil, ArErr{
|
||||
"TypeError",
|
||||
"unhashable type: '" + typeof(keyVal) + "'",
|
||||
m.line,
|
||||
m.path,
|
||||
m.code,
|
||||
true,
|
||||
}
|
||||
}
|
||||
newmap[keyVal] = valVal
|
||||
}
|
||||
return Map(newmap), ArErr{}
|
||||
}
|
||||
|
||||
func parseMap(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, bool, ArErr, int) {
|
||||
trimmed := strings.TrimSpace(code.code)
|
||||
trimmed = trimmed[1 : len(trimmed)-1]
|
||||
if len(trimmed) == 0 {
|
||||
return createMap{
|
||||
body: [][2]any{},
|
||||
code: code.realcode,
|
||||
line: code.line,
|
||||
path: code.path,
|
||||
}, true, ArErr{}, 1
|
||||
}
|
||||
var body [][2]any
|
||||
var LookingAtKey bool = true
|
||||
var current int
|
||||
var currentKey any
|
||||
var countIndex int = 1
|
||||
for i := 0; i < len(trimmed); i++ {
|
||||
var str string
|
||||
if LookingAtKey {
|
||||
if trimmed[i] != ':' {
|
||||
continue
|
||||
}
|
||||
str = trimmed[current:i]
|
||||
} else {
|
||||
if trimmed[i] != ',' && i != len(trimmed)-1 {
|
||||
continue
|
||||
}
|
||||
if i == len(trimmed)-1 {
|
||||
str = trimmed[current:]
|
||||
} else {
|
||||
str = trimmed[current:i]
|
||||
}
|
||||
}
|
||||
var value any
|
||||
if LookingAtKey && variableCompile.MatchString(str) {
|
||||
value = strings.TrimSpace(str)
|
||||
} else {
|
||||
val1, worked, err, indexcounted := translateVal(UNPARSEcode{code: str, realcode: code.realcode, line: code.line, path: code.path}, index, codelines, 0)
|
||||
if !worked || err.EXISTS {
|
||||
if i == len(trimmed)-1 {
|
||||
return val1, worked, err, i
|
||||
}
|
||||
continue
|
||||
}
|
||||
value = val1
|
||||
countIndex += indexcounted - 1
|
||||
}
|
||||
if LookingAtKey {
|
||||
currentKey = value
|
||||
current = i + 1
|
||||
LookingAtKey = false
|
||||
} else {
|
||||
body = append(body, [2]any{currentKey, value})
|
||||
current = i + 1
|
||||
LookingAtKey = true
|
||||
}
|
||||
}
|
||||
return createMap{
|
||||
body: body,
|
||||
code: code.realcode,
|
||||
line: code.line,
|
||||
path: code.path,
|
||||
}, true, ArErr{}, countIndex
|
||||
}
|
||||
|
||||
func Map(m anymap) ArObject {
|
||||
var mutex = sync.RWMutex{}
|
||||
return ArObject{
|
||||
var listenersMutex = sync.RWMutex{}
|
||||
|
||||
func Map(m anymap) ArObject {
|
||||
var currentID uint32 = 0
|
||||
listeners := map[any]map[uint32]any{}
|
||||
obj := ArObject{
|
||||
obj: anymap{
|
||||
"__value__": m,
|
||||
"__name__": "map",
|
||||
@@ -79,12 +171,29 @@ func Map(m anymap) ArObject {
|
||||
return false, ArErr{}
|
||||
}
|
||||
mutex.RLock()
|
||||
if _, ok := m[key]; !ok {
|
||||
mutex.RUnlock()
|
||||
return false, ArErr{}
|
||||
}
|
||||
if _, ok := m[key]; ok {
|
||||
mutex.RUnlock()
|
||||
return true, ArErr{}
|
||||
}
|
||||
for k := range m {
|
||||
compare, err := runOperation(
|
||||
operationType{
|
||||
operation: 9,
|
||||
values: []any{key, k},
|
||||
},
|
||||
stack{},
|
||||
0,
|
||||
)
|
||||
if err.EXISTS {
|
||||
continue
|
||||
}
|
||||
if anyToBool(compare) {
|
||||
mutex.RUnlock()
|
||||
return true, ArErr{}
|
||||
}
|
||||
}
|
||||
mutex.RUnlock()
|
||||
return false, ArErr{}
|
||||
},
|
||||
},
|
||||
"__NotContains__": builtinFunc{
|
||||
@@ -102,12 +211,29 @@ func Map(m anymap) ArObject {
|
||||
return true, ArErr{}
|
||||
}
|
||||
mutex.RLock()
|
||||
if _, ok := m[key]; !ok {
|
||||
mutex.RUnlock()
|
||||
return true, ArErr{}
|
||||
}
|
||||
if _, ok := m[key]; ok {
|
||||
mutex.RUnlock()
|
||||
return false, ArErr{}
|
||||
}
|
||||
for k := range m {
|
||||
compare, err := runOperation(
|
||||
operationType{
|
||||
operation: 9,
|
||||
values: []any{key, k},
|
||||
},
|
||||
stack{},
|
||||
0,
|
||||
)
|
||||
if err.EXISTS {
|
||||
continue
|
||||
}
|
||||
if anyToBool(compare) {
|
||||
mutex.RUnlock()
|
||||
return false, ArErr{}
|
||||
}
|
||||
}
|
||||
mutex.RUnlock()
|
||||
return true, ArErr{}
|
||||
},
|
||||
},
|
||||
"__setindex__": builtinFunc{
|
||||
@@ -128,6 +254,20 @@ func Map(m anymap) ArObject {
|
||||
}
|
||||
}
|
||||
key := ArValidToAny(args[0])
|
||||
listenersMutex.RLock()
|
||||
if _, ok := listeners[key]; ok {
|
||||
for _, v := range listeners[key] {
|
||||
runCall(
|
||||
call{
|
||||
Callable: v,
|
||||
Args: []any{args[1]},
|
||||
},
|
||||
stack{},
|
||||
0,
|
||||
)
|
||||
}
|
||||
}
|
||||
listenersMutex.RUnlock()
|
||||
mutex.Lock()
|
||||
m[key] = args[1]
|
||||
mutex.Unlock()
|
||||
@@ -153,19 +293,197 @@ func Map(m anymap) ArObject {
|
||||
}
|
||||
}
|
||||
mutex.RLock()
|
||||
if _, ok := m[key]; !ok {
|
||||
if v, ok := m[key]; ok {
|
||||
mutex.RUnlock()
|
||||
return v, ArErr{}
|
||||
}
|
||||
for k := range m {
|
||||
compare, err := runOperation(
|
||||
operationType{
|
||||
operation: 9,
|
||||
values: []any{key, k},
|
||||
},
|
||||
stack{},
|
||||
0,
|
||||
)
|
||||
if err.EXISTS {
|
||||
continue
|
||||
}
|
||||
if anyToBool(compare) {
|
||||
mutex.RUnlock()
|
||||
return m[k], ArErr{}
|
||||
}
|
||||
}
|
||||
mutex.RUnlock()
|
||||
return nil, ArErr{
|
||||
TYPE: "KeyError",
|
||||
message: "key " + fmt.Sprint(key) + " not found",
|
||||
EXISTS: true,
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
v := m[key]
|
||||
obj.obj["__Equal__"] = builtinFunc{
|
||||
"__Equal__",
|
||||
func(args ...any) (any, ArErr) {
|
||||
debugPrintln("Equal", args)
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if typeof(args[0]) != "map" {
|
||||
return false, ArErr{}
|
||||
}
|
||||
a := ArValidToAny(args[0]).(anymap)
|
||||
mutex.RLock()
|
||||
if len(m) != len(a) {
|
||||
mutex.RUnlock()
|
||||
return v, ArErr{}
|
||||
},
|
||||
},
|
||||
},
|
||||
return false, ArErr{}
|
||||
}
|
||||
for k, v := range m {
|
||||
debugPrintln(k, v)
|
||||
if _, ok := a[k]; !ok {
|
||||
mutex.RUnlock()
|
||||
return false, ArErr{}
|
||||
}
|
||||
val, err := runOperation(operationType{
|
||||
operation: 9,
|
||||
values: []any{v, a[k]},
|
||||
}, stack{}, 0)
|
||||
if err.EXISTS {
|
||||
return val, err
|
||||
}
|
||||
if !anyToBool(val) {
|
||||
mutex.RUnlock()
|
||||
return false, ArErr{}
|
||||
}
|
||||
}
|
||||
mutex.RUnlock()
|
||||
return true, ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["copy"] = builtinFunc{
|
||||
"copy",
|
||||
func(args ...any) (any, ArErr) {
|
||||
debugPrintln("copy", args)
|
||||
if len(args) != 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
mutex.RLock()
|
||||
newMap := make(anymap)
|
||||
for k, v := range m {
|
||||
newMap[k] = v
|
||||
}
|
||||
mutex.RUnlock()
|
||||
return newMap, ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["addKeyChangeListener"] = builtinFunc{
|
||||
"addKeyChangeListener",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 2 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected 2 arguments, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
key := ArValidToAny(args[0])
|
||||
if isUnhashable(key) {
|
||||
return nil, ArErr{
|
||||
TYPE: "Runtime Error",
|
||||
message: "unhashable type: " + typeof(args[0]),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if typeof(args[1]) != "function" {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected function, got " + typeof(args[1]),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
id := currentID
|
||||
currentID++
|
||||
listenersMutex.Lock()
|
||||
if _, ok := listeners[key]; !ok {
|
||||
listeners[key] = map[uint32]any{}
|
||||
}
|
||||
listeners[key][id] = args[1]
|
||||
listenersMutex.Unlock()
|
||||
return anymap{
|
||||
"remove": builtinFunc{
|
||||
"remove",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
listenersMutex.Lock()
|
||||
delete(listeners[key], id)
|
||||
listenersMutex.Unlock()
|
||||
return nil, ArErr{}
|
||||
},
|
||||
},
|
||||
}, ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["keys"] = builtinFunc{
|
||||
"keys",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
mutex.RLock()
|
||||
keys := []any{}
|
||||
for k := range m {
|
||||
keys = append(keys, AnyToArValid(k))
|
||||
}
|
||||
mutex.RUnlock()
|
||||
return ArArray(keys), ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["__Boolean__"] = builtinFunc{
|
||||
"__Boolean__",
|
||||
func(args ...any) (any, ArErr) {
|
||||
mutex.RLock()
|
||||
if len(m) == 0 {
|
||||
mutex.RUnlock()
|
||||
return false, ArErr{}
|
||||
}
|
||||
mutex.RUnlock()
|
||||
return true, ArErr{}
|
||||
},
|
||||
}
|
||||
obj.obj["object"] = builtinFunc{
|
||||
"object",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 0 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return ArObject{
|
||||
obj: m,
|
||||
}, ArErr{}
|
||||
},
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ var negativeCompile = makeRegex(`( *)-(.|\n)+( *)`)
|
||||
|
||||
type negative struct {
|
||||
VAL any
|
||||
sign bool
|
||||
line int
|
||||
code string
|
||||
path string
|
||||
@@ -15,15 +16,20 @@ func isNegative(code UNPARSEcode) bool {
|
||||
return negativeCompile.MatchString(code.code)
|
||||
}
|
||||
|
||||
func parseNegative(code UNPARSEcode, index int, codeline []UNPARSEcode) (negative, bool, ArErr, int) {
|
||||
func parseNegative(code UNPARSEcode, index int, codeline []UNPARSEcode) (any, bool, ArErr, int) {
|
||||
trimmed := strings.TrimSpace(code.code)
|
||||
trimmednegative := strings.TrimLeft(trimmed, "-")
|
||||
difference := len(trimmed) - len(trimmednegative)
|
||||
resp, worked, err, i := translateVal(UNPARSEcode{
|
||||
code: strings.TrimSpace(code.code)[1:],
|
||||
code: trimmednegative,
|
||||
realcode: code.realcode,
|
||||
line: code.line,
|
||||
path: code.path,
|
||||
}, index, codeline, 0)
|
||||
|
||||
return negative{
|
||||
VAL: resp,
|
||||
sign: difference%2 == 0,
|
||||
line: code.line,
|
||||
code: code.realcode,
|
||||
path: code.path,
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var numberCompile = makeRegex("( *)(-)?((([0-9]+(\\.[0-9]+)?)|(\\.[0-9]+))(e((\\-|\\+)?([0-9]+(\\.[0-9]+)?)))?)( *)")
|
||||
var numberCompile = makeRegex("( *)(-)?(((([0-9]+(\\.[0-9]+)?)|(\\.[0-9]+))(e((\\-|\\+)?([0-9]+(\\.[0-9]+)?)))?)|([0-9]+/[0-9]+))( *)")
|
||||
var binaryCompile = makeRegex("( *)(-)?(0b[10]+(.\\[10]+)?(e((\\-|\\+)?([0-9]+(\\.[0-9]+)?)))?)( *)")
|
||||
var hexCompile = makeRegex("( *)(-)?(0x[a-fA-F0-9]+(\\.[a-fA-F0-9]+)?)( *)")
|
||||
var octalCompile = makeRegex("( *)(-)?(0o[0-7]+(\\.[0-7]+)?(e((\\-|\\+)?([0-9]+(\\.[0-9]+)?)))?)( *)")
|
||||
@@ -15,7 +15,7 @@ var octalCompile = makeRegex("( *)(-)?(0o[0-7]+(\\.[0-7]+)?(e((\\-|\\+)?([0-9]+(
|
||||
type number = *big.Rat
|
||||
|
||||
// create a new number type
|
||||
func newNumber() *big.Rat {
|
||||
func newNumber() number {
|
||||
return new(big.Rat)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,47 +4,30 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var operations = [][]string{
|
||||
{
|
||||
var operations = []string{
|
||||
"&&",
|
||||
" and ",
|
||||
}, {
|
||||
"||",
|
||||
" or ",
|
||||
}, {
|
||||
" not in ",
|
||||
}, {
|
||||
" in ",
|
||||
}, {
|
||||
"<=",
|
||||
}, {
|
||||
">=",
|
||||
}, {
|
||||
"<",
|
||||
}, {
|
||||
">",
|
||||
}, {
|
||||
"!=",
|
||||
}, {
|
||||
"==",
|
||||
}, {
|
||||
"+",
|
||||
}, {
|
||||
"-",
|
||||
}, {
|
||||
"*",
|
||||
}, {
|
||||
"%",
|
||||
}, {
|
||||
"//",
|
||||
}, {
|
||||
"/",
|
||||
}, {
|
||||
"^",
|
||||
"**",
|
||||
}}
|
||||
}
|
||||
|
||||
var one = newNumber().SetInt64(1)
|
||||
|
||||
type operationType struct {
|
||||
operation int
|
||||
@@ -56,49 +39,52 @@ type operationType struct {
|
||||
|
||||
func parseOperations(code UNPARSEcode, index int, codelines []UNPARSEcode) (operationType, bool, ArErr, int) {
|
||||
for i := 0; i < len(operations); i++ {
|
||||
values := []any{}
|
||||
current := 0
|
||||
totalindex := 1
|
||||
for l := 0; l < len(code.code); l++ {
|
||||
for j := 0; j < len(operations[i]); j++ {
|
||||
if len(code.code[l:]) >= len(operations[i][j]) && code.code[l:l+len(operations[i][j])] == operations[i][j] {
|
||||
|
||||
resp, success, _, respindex := translateVal(
|
||||
split := strings.Split(code.code, operations[i])
|
||||
if len(split) < 2 {
|
||||
continue
|
||||
}
|
||||
var values []any
|
||||
lookingAt := 0
|
||||
totalStep := 1
|
||||
for j := 1; j < len(split); j++ {
|
||||
if split[j-1] == "" {
|
||||
continue
|
||||
}
|
||||
joined := strings.Join(split[lookingAt:j], operations[i])
|
||||
resp, success, err, respindex := translateVal(
|
||||
UNPARSEcode{
|
||||
code: code.code[current:l],
|
||||
code: joined,
|
||||
realcode: code.realcode,
|
||||
line: code.line,
|
||||
path: code.path,
|
||||
}, index, codelines, 0)
|
||||
|
||||
if success {
|
||||
totalindex += respindex - 1
|
||||
if !success || err.EXISTS {
|
||||
continue
|
||||
}
|
||||
values = append(values, resp)
|
||||
current = l + len(operations[i][j])
|
||||
}
|
||||
}
|
||||
}
|
||||
totalStep += respindex - 1
|
||||
lookingAt = j
|
||||
}
|
||||
if len(values) > 0 {
|
||||
resp, success, err, respindex := translateVal(
|
||||
UNPARSEcode{
|
||||
code: code.code[current:],
|
||||
code: strings.Join(split[lookingAt:], operations[i]),
|
||||
realcode: code.realcode,
|
||||
line: code.line,
|
||||
path: code.path,
|
||||
}, index, codelines, 0)
|
||||
if success {
|
||||
totalindex += respindex - 1
|
||||
values = append(values, resp)
|
||||
return operationType{
|
||||
i,
|
||||
values,
|
||||
code.line,
|
||||
code.realcode,
|
||||
code.path,
|
||||
}, true, err, totalindex
|
||||
if !success || err.EXISTS {
|
||||
return operationType{}, success, err, 0
|
||||
}
|
||||
return operationType{}, false, err, totalindex
|
||||
values = append(values, resp)
|
||||
totalStep += respindex - 1
|
||||
return operationType{
|
||||
operation: i,
|
||||
values: values,
|
||||
line: code.line,
|
||||
code: code.code,
|
||||
path: code.path,
|
||||
}, true, ArErr{}, totalStep
|
||||
}
|
||||
}
|
||||
return operationType{}, false, ArErr{}, 0
|
||||
@@ -129,7 +115,6 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
||||
stack,
|
||||
stacklevel+1,
|
||||
)
|
||||
resp2 = ArValidToAny(resp2)
|
||||
if err.EXISTS {
|
||||
return false, err
|
||||
}
|
||||
@@ -243,9 +228,9 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
||||
true,
|
||||
}
|
||||
case 8:
|
||||
return notequals(resp, resp2, o, stack, stacklevel)
|
||||
return notequals(resp, resp2, o, stack, stacklevel+1)
|
||||
case 9:
|
||||
return equals(resp, resp2, o, stack, stacklevel)
|
||||
return equals(resp, resp2, o, stack, stacklevel+1)
|
||||
default:
|
||||
return false, ArErr{
|
||||
"Runtime Error",
|
||||
@@ -338,6 +323,16 @@ func calcDivide(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||
return nil, err
|
||||
}
|
||||
if typeof(resp) == "number" && typeof(output) == "number" {
|
||||
if resp.(number).Cmp(newNumber().SetInt64(0)) == 0 {
|
||||
return nil, ArErr{
|
||||
"Runtime Error",
|
||||
"Cannot divide by zero",
|
||||
o.line,
|
||||
o.path,
|
||||
o.code,
|
||||
true,
|
||||
}
|
||||
}
|
||||
output = output.(number).Quo(output.(number), resp.(number))
|
||||
continue
|
||||
} else if x, ok := output.(ArObject); ok {
|
||||
@@ -641,16 +636,32 @@ func notequals(a any, b any, o operationType, stack stack, stacklevel int) (bool
|
||||
o.line,
|
||||
o.path,
|
||||
}, stack, stacklevel+1)
|
||||
if !err.EXISTS {
|
||||
return anyToBool(val), ArErr{}
|
||||
}
|
||||
}
|
||||
}
|
||||
if x, ok := b.(ArObject); ok {
|
||||
if y, ok := x.obj["__NotEqual__"]; ok {
|
||||
val, err := runCall(
|
||||
call{
|
||||
y,
|
||||
[]any{a},
|
||||
o.code,
|
||||
o.line,
|
||||
o.path,
|
||||
}, stack, stacklevel+1)
|
||||
if err.EXISTS {
|
||||
return false, err
|
||||
}
|
||||
return !anyToBool(val), ArErr{}
|
||||
return anyToBool(val), ArErr{}
|
||||
}
|
||||
}
|
||||
return !reflect.DeepEqual(a, b), ArErr{}
|
||||
}
|
||||
|
||||
func equals(a any, b any, o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
||||
debugPrintln("equals", a, b)
|
||||
if typeof(a) == "number" && typeof(b) == "number" {
|
||||
return a.(number).Cmp(b.(number)) == 0, ArErr{}
|
||||
} else if x, ok := a.(ArObject); ok {
|
||||
@@ -663,6 +674,21 @@ func equals(a any, b any, o operationType, stack stack, stacklevel int) (bool, A
|
||||
o.line,
|
||||
o.path,
|
||||
}, stack, stacklevel+1)
|
||||
if !err.EXISTS {
|
||||
return anyToBool(val), ArErr{}
|
||||
}
|
||||
}
|
||||
}
|
||||
if x, ok := b.(ArObject); ok {
|
||||
if y, ok := x.obj["__GreaterThanEqual__"]; ok {
|
||||
val, err := runCall(
|
||||
call{
|
||||
y,
|
||||
[]any{a},
|
||||
o.code,
|
||||
o.line,
|
||||
o.path,
|
||||
}, stack, stacklevel+1)
|
||||
if err.EXISTS {
|
||||
return false, err
|
||||
}
|
||||
@@ -678,7 +704,6 @@ func calcMod(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||
stack,
|
||||
stacklevel+1,
|
||||
)
|
||||
resp = ArValidToAny(resp)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
@@ -756,7 +781,7 @@ func calcIntDiv(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||
return nil, err
|
||||
}
|
||||
if typeof(resp) == "number" && typeof(output) == "number" {
|
||||
output = output.(number).Quo(output.(number), resp.(number))
|
||||
output = floor(output.(number).Quo(output.(number), resp.(number)))
|
||||
continue
|
||||
} else if x, ok := output.(ArObject); ok {
|
||||
if y, ok := x.obj["__IntDivide__"]; ok {
|
||||
@@ -819,12 +844,49 @@ func calcPower(o operationType, stack stack, stacklevel int) (number, ArErr) {
|
||||
return nil, err
|
||||
}
|
||||
if typeof(resp) == "number" {
|
||||
n := newNumber().Set(resp.(number))
|
||||
if n.Cmp(newNumber().SetInt64(10)) <= 0 {
|
||||
toOut := newNumber().SetInt64(1)
|
||||
clone := newNumber().Set(output)
|
||||
nAbs := (abs(newNumber().Set(n)))
|
||||
j := newNumber()
|
||||
for ; j.Cmp(nAbs) < 0; j.Add(j, one) {
|
||||
toOut.Mul(toOut, clone)
|
||||
}
|
||||
|
||||
nAbs.Sub(nAbs, j)
|
||||
if nAbs.Cmp(newNumber()) < 0 {
|
||||
j.Sub(j, one)
|
||||
n1, _ := toOut.Float64()
|
||||
n2, _ := nAbs.Float64()
|
||||
calculated := newNumber().SetFloat64(math.Pow(n1, n2))
|
||||
if calculated == nil {
|
||||
calculated = infinity
|
||||
}
|
||||
toOut.Mul(toOut, calculated)
|
||||
}
|
||||
if n.Cmp(newNumber()) < 0 {
|
||||
toOut.Quo(newNumber().SetInt64(1), toOut)
|
||||
}
|
||||
output.Set(toOut)
|
||||
} else if n.Cmp(newNumber().SetInt64(1)) != 0 {
|
||||
n1, _ := output.Float64()
|
||||
n2, _ := n.Float64()
|
||||
calculated := newNumber().SetFloat64(math.Pow(n1, n2))
|
||||
if calculated == nil {
|
||||
calculated = infinity
|
||||
}
|
||||
output.Mul(output, calculated)
|
||||
}
|
||||
|
||||
/*
|
||||
n1, _ := output.Float64()
|
||||
n2, _ := resp.(number).Float64()
|
||||
output = newNumber().SetFloat64(math.Pow(n1, n2))
|
||||
if output == nil {
|
||||
output = infinity
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
return nil, ArErr{
|
||||
"Runtime Error",
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var genericImportCompiled = makeRegex(`import( )+(.|\n)+( )+as( )+([a-zA-Z_]|(\p{L}\p{M}*))([a-zA-Z0-9_]|(\p{L}\p{M}*))*( *)`)
|
||||
var genericImportCompiled = makeRegex(`import( )+(.|\n)+(( )+as( )+([a-zA-Z_]|(\p{L}\p{M}*))([a-zA-Z0-9_]|(\p{L}\p{M}*))*)?( *)`)
|
||||
|
||||
type ArImport struct {
|
||||
filePath any
|
||||
values any
|
||||
code string
|
||||
line int
|
||||
path string
|
||||
FilePath any
|
||||
Values any
|
||||
Code string
|
||||
Line int
|
||||
Path string
|
||||
}
|
||||
|
||||
func isGenericImport(code UNPARSEcode) bool {
|
||||
@@ -22,18 +22,51 @@ func isGenericImport(code UNPARSEcode) bool {
|
||||
func parseGenericImport(code UNPARSEcode, index int, codeline []UNPARSEcode) (ArImport, bool, ArErr, int) {
|
||||
trim := strings.Trim(code.code, " ")
|
||||
pathAndAs := trim[6:]
|
||||
split := strings.SplitN(pathAndAs, " as ", 2)
|
||||
toImportstr := strings.TrimSpace(split[0])
|
||||
asStr := strings.TrimSpace(split[1])
|
||||
toImport, worked, err, i := translateVal(UNPARSEcode{
|
||||
code: toImportstr,
|
||||
split := strings.Split(pathAndAs, " as ")
|
||||
var toImport any
|
||||
var asStr any
|
||||
var i = 1
|
||||
if len(split) == 1 {
|
||||
toImportval, worked, err, I := translateVal(UNPARSEcode{
|
||||
code: strings.Trim(split[0], " "),
|
||||
realcode: code.realcode,
|
||||
line: code.line,
|
||||
path: code.path,
|
||||
}, index, codeline, 0)
|
||||
if !worked {
|
||||
return ArImport{}, false, err, i
|
||||
if !worked || err.EXISTS {
|
||||
return ArImport{}, worked, err, I
|
||||
}
|
||||
toImport = toImportval
|
||||
i = I
|
||||
} else {
|
||||
for i := 1; i < len(split); i++ {
|
||||
before := strings.Trim(strings.Join(split[:i], " as "), " ")
|
||||
after := strings.Trim(strings.Join(split[i:], " as "), " ")
|
||||
toImportval, worked, err, I := translateVal(UNPARSEcode{
|
||||
code: before,
|
||||
realcode: code.realcode,
|
||||
line: code.line,
|
||||
path: code.path,
|
||||
}, index, codeline, 0)
|
||||
i = I
|
||||
if !worked || err.EXISTS {
|
||||
if i == len(split)-1 {
|
||||
return ArImport{}, worked, err, i
|
||||
}
|
||||
continue
|
||||
}
|
||||
if after == "" {
|
||||
} else if after == "*" {
|
||||
asStr = true
|
||||
} else if variableCompile.MatchString(after) {
|
||||
asStr = after
|
||||
} else {
|
||||
return ArImport{}, false, ArErr{"Syntax Error", "invalid variable name '" + after + "'", code.line, code.path, code.realcode, true}, i
|
||||
}
|
||||
toImport = toImportval
|
||||
}
|
||||
}
|
||||
|
||||
return ArImport{
|
||||
toImport,
|
||||
asStr,
|
||||
@@ -44,44 +77,72 @@ func parseGenericImport(code UNPARSEcode, index int, codeline []UNPARSEcode) (Ar
|
||||
}
|
||||
|
||||
func runImport(importOBJ ArImport, stack stack, stacklevel int) (any, ArErr) {
|
||||
return nil, ArErr{"Import Error", "importing in WASM is currently not supported", importOBJ.line, importOBJ.path, importOBJ.code, true}
|
||||
val, err := runVal(importOBJ.filePath, stack, stacklevel+1)
|
||||
val, err := runVal(importOBJ.FilePath, stack, stacklevel+1)
|
||||
val = ArValidToAny(val)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
if typeof(val) != "string" {
|
||||
return nil, ArErr{"Type Error", "import requires a string, got type '" + typeof(val) + "'", importOBJ.line, importOBJ.path, importOBJ.code, true}
|
||||
return nil, ArErr{"Type Error", "import requires a string, got type '" + typeof(val) + "'", importOBJ.Line, importOBJ.Path, importOBJ.Code, true}
|
||||
}
|
||||
path := val.(string)
|
||||
ex, e := os.Getwd()
|
||||
if e != nil {
|
||||
return nil, ArErr{"File Error", "could not get current working directory", importOBJ.line, importOBJ.path, importOBJ.code, true}
|
||||
}
|
||||
stackMap, err := importMod(path, ex, false, stack[0])
|
||||
parent := filepath.Dir(filepath.ToSlash(importOBJ.Path))
|
||||
stackMap, err := importMod(path, parent, false, stack[0])
|
||||
if err.EXISTS {
|
||||
if err.line == 0 {
|
||||
err.line = importOBJ.line
|
||||
err.line = importOBJ.Line
|
||||
}
|
||||
if err.path == "" {
|
||||
err.path = importOBJ.path
|
||||
err.path = importOBJ.Path
|
||||
}
|
||||
if err.code == "" {
|
||||
err.code = importOBJ.code
|
||||
err.code = importOBJ.Code
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
switch x := importOBJ.values.(type) {
|
||||
setindex, ok := stack[len(stack)-1].obj["__setindex__"]
|
||||
if !ok {
|
||||
return nil, ArErr{
|
||||
"Import Error",
|
||||
"could not find __setindex__ in module scope",
|
||||
importOBJ.Line,
|
||||
importOBJ.Path,
|
||||
importOBJ.Code,
|
||||
true,
|
||||
}
|
||||
}
|
||||
switch x := importOBJ.Values.(type) {
|
||||
case []string:
|
||||
for _, v := range x {
|
||||
val, ok := stackMap.obj[v]
|
||||
if !ok {
|
||||
return nil, ArErr{"Import Error", "could not find value " + anyToArgon(v, true, false, 3, 0, false, 0) + " in module " + anyToArgon(path, true, false, 3, 0, false, 0), importOBJ.line, importOBJ.path, importOBJ.code, true}
|
||||
return nil, ArErr{"Import Error", "could not find value " + anyToArgon(v, true, false, 3, 0, false, 0) + " in module " + anyToArgon(path, true, false, 3, 0, false, 0), importOBJ.Line, importOBJ.Path, importOBJ.Code, true}
|
||||
}
|
||||
stack[len(stack)-1].obj[v] = val
|
||||
builtinCall(setindex, []any{v, val})
|
||||
}
|
||||
case string:
|
||||
stack[len(stack)-1].obj[x] = stackMap
|
||||
builtinCall(setindex, []any{x, stackMap})
|
||||
case bool:
|
||||
keyGetter, ok := stackMap.obj["keys"]
|
||||
if !ok {
|
||||
return nil, ArErr{"Import Error", "could not find keys in module scope", importOBJ.Line, importOBJ.Path, importOBJ.Code, true}
|
||||
}
|
||||
valueGetter, ok := stackMap.obj["__getindex__"]
|
||||
if !ok {
|
||||
return nil, ArErr{"Import Error", "could not find __getindex__ in module scope", importOBJ.Line, importOBJ.Path, importOBJ.Code, true}
|
||||
}
|
||||
keys, err := builtinCall(keyGetter, []any{})
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
keys = ArValidToAny(keys)
|
||||
for _, v := range keys.([]any) {
|
||||
val, err := builtinCall(valueGetter, []any{v})
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
builtinCall(setindex, []any{v, val})
|
||||
}
|
||||
}
|
||||
return nil, ArErr{}
|
||||
}
|
||||
|
||||
244
src/path.go
Normal file
244
src/path.go
Normal file
@@ -0,0 +1,244 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var ArPath = Map(
|
||||
anymap{
|
||||
"ReadDir": builtinFunc{
|
||||
"ReadDir",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "ReadDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
args[0] = ArValidToAny(args[0])
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "ReadDir argument must be a string, got " + typeof(args[0]),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
files, err := os.ReadDir(args[0].(string))
|
||||
if err != nil {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: err.Error(),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
var ret []any
|
||||
for _, file := range files {
|
||||
ret = append(ret, file.Name())
|
||||
}
|
||||
return ret, ArErr{}
|
||||
}},
|
||||
"exists": builtinFunc{
|
||||
"exists",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "exists takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
args[0] = ArValidToAny(args[0])
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "exists argument must be a string, got " + typeof(args[0]),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
_, err := os.Stat(args[0].(string))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return false, ArErr{}
|
||||
}
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: err.Error(),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return true, ArErr{}
|
||||
}},
|
||||
"mkAllDir": builtinFunc{
|
||||
"mkAllDir",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "mkAllDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
args[0] = ArValidToAny(args[0])
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "mkAllDir argument must be a string, got " + typeof(args[0]),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
err := os.MkdirAll(args[0].(string), os.ModePerm)
|
||||
if err != nil {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: err.Error(),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"mkDir": builtinFunc{
|
||||
"mkDir",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "mkDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
args[0] = ArValidToAny(args[0])
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "mkDir argument must be a string, got " + typeof(args[0]),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
err := os.Mkdir(args[0].(string), os.ModePerm)
|
||||
if err != nil {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: err.Error(),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"remove": builtinFunc{
|
||||
"remove",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "remove takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
args[0] = ArValidToAny(args[0])
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "remove argument must be a string, got " + typeof(args[0]),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
err := os.Remove(args[0].(string))
|
||||
if err != nil {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: err.Error(),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"isDir": builtinFunc{
|
||||
"isDir",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "isDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
args[0] = ArValidToAny(args[0])
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "isDir argument must be a string, got " + typeof(args[0]),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
stat, err := os.Stat(args[0].(string))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return false, ArErr{}
|
||||
}
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: err.Error(),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return stat.IsDir(), ArErr{}
|
||||
}},
|
||||
"join": builtinFunc{
|
||||
"join",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "join takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
args[0] = ArValidToAny(args[0])
|
||||
switch arr := args[0].(type) {
|
||||
case []any:
|
||||
var Path []string
|
||||
for _, x := range arr {
|
||||
x = ArValidToAny(x)
|
||||
if typeof(x) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "join argument must be an array of strings, got " + typeof(x),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
Path = append(Path, x.(string))
|
||||
}
|
||||
return filepath.Join(Path...), ArErr{}
|
||||
}
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "join argument must be an array, got " + typeof(args[0]),
|
||||
EXISTS: true,
|
||||
}
|
||||
}},
|
||||
"parent": builtinFunc{
|
||||
"parent",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "parent takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
args[0] = ArValidToAny(args[0])
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "parent argument must be a string, got " + typeof(args[0]),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return path.Dir(filepath.ToSlash(args[0].(string))), ArErr{}
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import "github.com/wadey/go-rounding"
|
||||
import (
|
||||
"github.com/wadey/go-rounding"
|
||||
)
|
||||
|
||||
func floor(x number) number {
|
||||
|
||||
|
||||
33
src/run.go
33
src/run.go
@@ -18,9 +18,9 @@ func runVal(line any, stack stack, stacklevel int) (any, ArErr) {
|
||||
return ArString(x), ArErr{}
|
||||
case call:
|
||||
if stackoverflow {
|
||||
linenum = x.line
|
||||
path = x.path
|
||||
code = x.code
|
||||
linenum = x.Line
|
||||
path = x.Path
|
||||
code = x.Code
|
||||
break
|
||||
}
|
||||
return runCall(x, stack, stacklevel+1)
|
||||
@@ -34,17 +34,17 @@ func runVal(line any, stack stack, stacklevel int) (any, ArErr) {
|
||||
return runFactorial(x, stack, stacklevel+1)
|
||||
case accessVariable:
|
||||
if stackoverflow {
|
||||
linenum = x.line
|
||||
path = x.path
|
||||
code = x.code
|
||||
linenum = x.Line
|
||||
path = x.Path
|
||||
code = x.Code
|
||||
break
|
||||
}
|
||||
return readVariable(x, stack)
|
||||
case ArMapGet:
|
||||
if stackoverflow {
|
||||
linenum = x.line
|
||||
path = x.path
|
||||
code = x.code
|
||||
linenum = x.Line
|
||||
path = x.Path
|
||||
code = x.Code
|
||||
break
|
||||
}
|
||||
return mapGet(x, stack, stacklevel+1)
|
||||
@@ -70,8 +70,11 @@ func runVal(line any, stack stack, stacklevel int) (any, ArErr) {
|
||||
}
|
||||
switch y := resp.(type) {
|
||||
case number:
|
||||
if !x.sign {
|
||||
return newNumber().Neg(y), ArErr{}
|
||||
}
|
||||
return y, ArErr{}
|
||||
}
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "cannot negate a non-number",
|
||||
@@ -181,13 +184,21 @@ func runVal(line any, stack stack, stacklevel int) (any, ArErr) {
|
||||
break
|
||||
}
|
||||
return runSquareroot(x, stack, stacklevel+1)
|
||||
case ArImport:
|
||||
case createMap:
|
||||
if stackoverflow {
|
||||
linenum = x.line
|
||||
path = x.path
|
||||
code = x.code
|
||||
break
|
||||
}
|
||||
return runCreateMap(x, stack, stacklevel+1)
|
||||
case ArImport:
|
||||
if stackoverflow {
|
||||
linenum = x.Line
|
||||
path = x.Path
|
||||
code = x.Code
|
||||
break
|
||||
}
|
||||
return runImport(x, stack, stacklevel+1)
|
||||
case ABS:
|
||||
if stackoverflow {
|
||||
@@ -205,7 +216,7 @@ func runVal(line any, stack stack, stacklevel int) (any, ArErr) {
|
||||
break
|
||||
}
|
||||
return runTryCatch(x, stack, stacklevel+1)
|
||||
case bool, ArObject, number, nil:
|
||||
case bool, ArObject, number, nil, Callable, builtinFunc, anymap:
|
||||
return x, ArErr{}
|
||||
}
|
||||
if stackoverflow {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func ArSequence(a ...any) (any, ArErr) {
|
||||
if len(a) < 1 || len(a) > 2 {
|
||||
|
||||
13
src/sha256.go
Normal file
13
src/sha256.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func sha256Hash(s string) string {
|
||||
h := sha256.New()
|
||||
h.Write([]byte(s))
|
||||
bs := h.Sum(nil)
|
||||
return fmt.Sprintf("%x", bs)
|
||||
}
|
||||
29
src/shell.go
29
src/shell.go
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func shell(global ArObject) {
|
||||
@@ -18,23 +19,26 @@ func shell(global ArObject) {
|
||||
}
|
||||
}
|
||||
}()
|
||||
fmt.Print("\x1b[32;5;240mWelcome to the Argon v3!\x1b[0m\n\n")
|
||||
for {
|
||||
indo := false
|
||||
indent := 0
|
||||
previous := 0
|
||||
totranslate := []UNPARSEcode{}
|
||||
code := input("\x1b[38;5;240m>>> \x1b[0m\x1b[1;5;240m")
|
||||
fmt.Print("\x1b[0m")
|
||||
if code == "" {
|
||||
continue
|
||||
}
|
||||
indo = true
|
||||
totranslate = append(totranslate, UNPARSEcode{code, code, 1, "<shell>"})
|
||||
for i := 2; indo; i++ {
|
||||
code := input("\x1b[38;5;240m... \x1b[0m\x1b[1;5;240m")
|
||||
textBefore := ">>>"
|
||||
for i := 1; indent > 0 || (previous != indent && indent >= 0) || i == 1; i++ {
|
||||
indentStr := strings.Repeat(" ", indent)
|
||||
code := indentStr + input("\x1b[38;5;240m"+textBefore+indentStr+" \x1b[0m\x1b[1;5;240m")
|
||||
fmt.Print("\x1b[0m")
|
||||
totranslate = append(totranslate, UNPARSEcode{code, code, i, "<shell>"})
|
||||
if code == "" {
|
||||
indo = false
|
||||
trimmed := strings.TrimSpace(code)
|
||||
split := strings.Split(trimmed, " ")
|
||||
previous = indent
|
||||
if split[len(split)-1] == "do" {
|
||||
indent++
|
||||
} else if trimmed == "" {
|
||||
indent--
|
||||
}
|
||||
textBefore = "..."
|
||||
}
|
||||
translated, translationerr := translate(totranslate)
|
||||
count := len(translated)
|
||||
@@ -47,7 +51,6 @@ func shell(global ArObject) {
|
||||
if runimeErr.EXISTS {
|
||||
panicErr(runimeErr)
|
||||
} else if count == 1 {
|
||||
|
||||
fmt.Println(anyToArgon(output, true, true, 3, 0, true, 1))
|
||||
}
|
||||
}
|
||||
|
||||
528
src/socket.go
Normal file
528
src/socket.go
Normal file
@@ -0,0 +1,528 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
func ArSocketClient(args ...any) (any, ArErr) {
|
||||
if len(args) != 2 {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket takes exactly 2 arguments",
|
||||
EXISTS: true,
|
||||
}
|
||||
} else if typeof(args[0]) != "string" {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket type must be a string",
|
||||
EXISTS: true,
|
||||
}
|
||||
} else if typeof(args[1]) != "string" {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket address must be a string",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
networktype := ArValidToAny(args[0]).(string)
|
||||
address := ArValidToAny(args[1]).(string)
|
||||
conn, err := net.Dial(networktype, address)
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: fmt.Sprintf("Socket connection failed: %s", err.Error()),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return ArObject{
|
||||
obj: anymap{
|
||||
"read": builtinFunc{
|
||||
"read",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket.readData() takes exactly 1 argument",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if conn == nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Connection is closed",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
buf := make([]byte, args[0].(number).Num().Int64())
|
||||
n, err := conn.Read(buf)
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: fmt.Sprintf("Socket read failed: %s", err.Error()),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return ArBuffer(buf[:n]), ArErr{}
|
||||
}},
|
||||
"readUntil": builtinFunc{
|
||||
"readUntil",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket.readUntil() takes exactly 1 argument",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if conn == nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Connection is closed",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
value := ArValidToAny(args[0])
|
||||
if typeof(value) != "buffer" {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: fmt.Sprintf("Socket.readUntil() argument must be a buffer, not %s", typeof(value)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
endBuf := value.([]byte)
|
||||
reader := io.Reader(conn)
|
||||
buf := make([]byte, len(endBuf))
|
||||
var data []byte
|
||||
for {
|
||||
_, err := reader.Read(buf)
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: fmt.Sprintf("Socket read failed: %s", err.Error()),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
data = append(data, buf[0])
|
||||
if len(data) >= len(endBuf) {
|
||||
dataSlice := data[len(data)-len(endBuf):]
|
||||
for i := 0; i < len(endBuf); i++ {
|
||||
if dataSlice[i] != endBuf[i] {
|
||||
break
|
||||
}
|
||||
if i == len(endBuf)-1 {
|
||||
return ArBuffer(data), ArErr{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}},
|
||||
"write": builtinFunc{
|
||||
"write",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: fmt.Sprintf("write() takes exactly 1 argument (%d given)", len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if typeof(args[0]) != "buffer" {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: fmt.Sprintf("write() argument must be a buffer, not %s", typeof(args[0])),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if conn == nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Connection is closed",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
args[0] = ArValidToAny(args[0])
|
||||
if typeof(args[0]) != "buffer" {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: fmt.Sprintf("write() argument must be a buffer, not %s", typeof(args[0])),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
_, err := conn.Write(args[0].([]byte))
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: err.Error(),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"close": builtinFunc{
|
||||
"close",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if conn == nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Connection is already closed",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
err := conn.Close()
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: err.Error(),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
conn = nil
|
||||
return nil, ArErr{}
|
||||
},
|
||||
},
|
||||
"isClosed": builtinFunc{
|
||||
"isClosed",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if conn == nil {
|
||||
return true, ArErr{}
|
||||
}
|
||||
conn.SetWriteDeadline(time.Now().Add(1 * time.Millisecond))
|
||||
_, err := conn.Write([]byte{})
|
||||
conn.SetWriteDeadline(time.Time{})
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
conn = nil
|
||||
return true, ArErr{}
|
||||
}
|
||||
return false, ArErr{}
|
||||
|
||||
},
|
||||
},
|
||||
}}, ArErr{}
|
||||
}
|
||||
|
||||
func ArSocketServer(args ...any) (any, ArErr) {
|
||||
if len(args) != 2 {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket takes exactly 2 arguments",
|
||||
EXISTS: true,
|
||||
}
|
||||
} else if typeof(args[0]) != "string" {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket type must be a string",
|
||||
EXISTS: true,
|
||||
}
|
||||
} else if typeof(args[1]) != "number" {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket port must be a number",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
networktype := ArValidToAny(args[0]).(string)
|
||||
port := args[1].(number)
|
||||
if port.Denom().Int64() != 1 {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket port must be an integer",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
ln, err := net.Listen(networktype, ":"+fmt.Sprint(port.Num().Int64()))
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: err.Error(),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return Map(anymap{
|
||||
"accept": builtinFunc{
|
||||
"accept",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if ln == nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket is closed",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
conn, err := ln.Accept()
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: err.Error(),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return Map(anymap{
|
||||
"read": builtinFunc{
|
||||
"read",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket.readData() takes exactly 1 argument",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if conn == nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Connection is closed",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
buf := make([]byte, args[0].(number).Num().Int64())
|
||||
n, err := conn.Read(buf)
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: err.Error(),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return ArBuffer(buf[:n]), ArErr{}
|
||||
},
|
||||
},
|
||||
"readUntil": builtinFunc{
|
||||
"readUntil",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket.readUntil() takes exactly 1 argument",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if conn == nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Connection is closed",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
value := ArValidToAny(args[0])
|
||||
if typeof(value) != "buffer" {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: fmt.Sprintf("Socket.readUntil() argument must be a buffer, not %s", typeof(value)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
endBuf := value.([]byte)
|
||||
var data []byte
|
||||
buf := make([]byte, 1)
|
||||
lookingAt := 0
|
||||
for {
|
||||
n, err := io.ReadFull(conn, buf)
|
||||
if err != nil {
|
||||
return ArBuffer(data), ArErr{}
|
||||
}
|
||||
chunk := buf[:n]
|
||||
data = append(data, chunk...)
|
||||
for i := 0; i < n; i++ {
|
||||
if chunk[i] == endBuf[lookingAt] {
|
||||
lookingAt++
|
||||
if lookingAt == len(endBuf) {
|
||||
data = append(data, chunk...)
|
||||
return ArBuffer(data), ArErr{}
|
||||
}
|
||||
} else {
|
||||
lookingAt = 0
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}},
|
||||
"clearTimeout": builtinFunc{
|
||||
"clearTimeout",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 0 {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket.clearTimeout() takes exactly 0 arguments",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if conn == nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Connection is closed",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
conn.SetDeadline(time.Time{})
|
||||
return ArObject{}, ArErr{}
|
||||
},
|
||||
},
|
||||
"setTimeout": builtinFunc{
|
||||
"setTimeout",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket.setTimeout() takes exactly 1 argument",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if typeof(args[0]) != "number" {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket timeout must be a number",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if conn == nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Connection is closed",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
timeout := args[0].(number)
|
||||
if timeout.Denom().Int64() != 1 {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket timeout must be an integer",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
err := conn.SetDeadline(time.Now().Add(time.Duration(timeout.Num().Int64()) * time.Millisecond))
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: err.Error(),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return ArObject{}, ArErr{}
|
||||
},
|
||||
},
|
||||
"write": builtinFunc{
|
||||
"write",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket.writeData() takes exactly 1 argument",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if conn == nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Connection is closed",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
data := ArValidToAny(args[0])
|
||||
switch x := data.(type) {
|
||||
case []any:
|
||||
bytes := []byte{}
|
||||
for _, v := range x {
|
||||
if typeof(v) != "number" && v.(number).Denom().Int64() != 1 {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket.writeData() argument must be a array of integers",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
bytes = append(bytes, byte(v.(number).Num().Int64()))
|
||||
}
|
||||
conn.Write(bytes)
|
||||
return nil, ArErr{}
|
||||
case []byte:
|
||||
conn.Write(x)
|
||||
return nil, ArErr{}
|
||||
}
|
||||
return nil, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket.writeData() argument must be a array of numbers",
|
||||
}
|
||||
},
|
||||
},
|
||||
"close": builtinFunc{
|
||||
"close",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if conn == nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Connection is already closed",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
conn.Close()
|
||||
conn = nil
|
||||
return nil, ArErr{}
|
||||
},
|
||||
},
|
||||
"isClosed": builtinFunc{
|
||||
"isClosed",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if conn == nil {
|
||||
return true, ArErr{}
|
||||
}
|
||||
conn.SetWriteDeadline(time.Now().Add(1 * time.Millisecond))
|
||||
_, err := conn.Write([]byte{})
|
||||
conn.SetWriteDeadline(time.Time{})
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
conn = nil
|
||||
return true, ArErr{}
|
||||
}
|
||||
return false, ArErr{}
|
||||
|
||||
},
|
||||
},
|
||||
"RemoteAddr": builtinFunc{
|
||||
"RemoteAddr",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if conn == nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Connection is closed",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return ArString(conn.RemoteAddr().String()), ArErr{}
|
||||
},
|
||||
},
|
||||
"LocalAddr": builtinFunc{
|
||||
"LocalAddr",
|
||||
func(args ...any) (any, ArErr) {
|
||||
return ArString(conn.LocalAddr().String()), ArErr{}
|
||||
},
|
||||
},
|
||||
}), ArErr{}
|
||||
},
|
||||
},
|
||||
"close": builtinFunc{
|
||||
"close",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if ln == nil {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket is already closed",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
ln.Close()
|
||||
ln = nil
|
||||
return nil, ArErr{}
|
||||
},
|
||||
},
|
||||
"isClosed": builtinFunc{
|
||||
"isClosed",
|
||||
func(args ...any) (any, ArErr) {
|
||||
return ln == nil, ArErr{}
|
||||
},
|
||||
},
|
||||
}), ArErr{}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type keyCache map[any]any
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func quickSort(list []any, getKey func(any) (any, ArErr)) ([]any, ArErr) {
|
||||
if len(list) <= 1 {
|
||||
@@ -13,21 +13,19 @@ func quickSort(list []any, getKey func(any) (any, ArErr)) ([]any, ArErr) {
|
||||
var left []any
|
||||
var right []any
|
||||
|
||||
var cache = make(keyCache)
|
||||
|
||||
for _, v := range list[1:] {
|
||||
val, err := getkeyCache(getKey, v, cache)
|
||||
val, err := getkeyCache(getKey, v)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
pivotval, err := getkeyCache(getKey, pivot, cache)
|
||||
pivotval, err := getkeyCache(getKey, pivot)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
comp, comperr := compare(val, pivotval)
|
||||
if comperr != nil {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
TYPE: "Runtime Error",
|
||||
message: comperr.Error(),
|
||||
EXISTS: true,
|
||||
}
|
||||
@@ -51,16 +49,11 @@ func quickSort(list []any, getKey func(any) (any, ArErr)) ([]any, ArErr) {
|
||||
return append(append(left, pivot), right...), ArErr{}
|
||||
}
|
||||
|
||||
func getkeyCache(getKey func(any) (any, ArErr), index any, cache keyCache) (any, ArErr) {
|
||||
key := ArValidToAny(index)
|
||||
if cacheval, ok := cache[key]; ok {
|
||||
return cacheval, ArErr{}
|
||||
}
|
||||
val, err := getKey(index)
|
||||
func getkeyCache(getKey func(any) (any, ArErr), key any) (any, ArErr) {
|
||||
val, err := getKey(key)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
cache[key] = val
|
||||
return val, ArErr{}
|
||||
}
|
||||
|
||||
@@ -71,8 +64,8 @@ func compare(a, b any) (bool, error) {
|
||||
if y, ok := x.obj["__LessThan__"]; ok {
|
||||
resp, err := runCall(
|
||||
call{
|
||||
callable: y,
|
||||
args: []any{b},
|
||||
Callable: y,
|
||||
Args: []any{b},
|
||||
}, stack{}, 0)
|
||||
if !err.EXISTS {
|
||||
return anyToBool(resp), nil
|
||||
|
||||
@@ -15,21 +15,36 @@ func isString(code UNPARSEcode) bool {
|
||||
return stringCompile.MatchString(code.code)
|
||||
}
|
||||
|
||||
func swapQuotes(text string) string {
|
||||
result := ""
|
||||
for _, char := range text {
|
||||
switch char {
|
||||
case '"':
|
||||
result += "'"
|
||||
case '\'':
|
||||
result += "\""
|
||||
default:
|
||||
result += string(char)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func unquoted(
|
||||
str string,
|
||||
) (string, error) {
|
||||
str = strings.Trim(str, " ")
|
||||
if str[0] == '\'' {
|
||||
str = strings.Replace(str, "\\\"", "\"", -1)
|
||||
str = strings.Replace(str, "\"", "\\\"", -1)
|
||||
char := str[0]
|
||||
if char == '\'' {
|
||||
str = swapQuotes(str)
|
||||
}
|
||||
str = str[1 : len(str)-1]
|
||||
str = strings.Replace(str, "\\'", "'", -1)
|
||||
str = "\"" + str + "\""
|
||||
output, err := strconv.Unquote(str)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if char == '\'' {
|
||||
output = swapQuotes(output)
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
|
||||
@@ -39,7 +54,7 @@ func parseString(code UNPARSEcode) (string, bool, ArErr, int) {
|
||||
|
||||
unquoted, err := unquoted(trim)
|
||||
if err != nil {
|
||||
return "", false, ArErr{"Syntax Error", "invalid string", code.line, code.path, code.realcode, true}, 1
|
||||
return "", false, ArErr{"Syntax Error", "invalid escape sequence", code.line, code.path, code.realcode, true}, 1
|
||||
}
|
||||
|
||||
return unquoted, true, ArErr{}, 1
|
||||
@@ -254,7 +269,7 @@ func ArString(str string) ArObject {
|
||||
if typeof(a[0]) != "string" {
|
||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||
}
|
||||
splitby := a[0].(ArObject).obj["__value__"].(string)
|
||||
splitby := ArValidToAny(a[0]).(string)
|
||||
output := []any{}
|
||||
splitted := (strings.Split(str, splitby))
|
||||
for _, v := range splitted {
|
||||
@@ -262,6 +277,27 @@ func ArString(str string) ArObject {
|
||||
}
|
||||
return output, ArErr{}
|
||||
}}
|
||||
obj.obj["splitN"] = builtinFunc{
|
||||
"splitN",
|
||||
func(a ...any) (any, ArErr) {
|
||||
if len(a) != 2 {
|
||||
return nil, ArErr{"TypeError", "expected 2 or more argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||
}
|
||||
if typeof(a[0]) != "string" {
|
||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||
}
|
||||
if typeof(a[1]) != "number" || !a[1].(number).IsInt() {
|
||||
return nil, ArErr{"TypeError", "expected integer, got " + typeof(a[1]), 0, "", "", true}
|
||||
}
|
||||
splitby := ArValidToAny(a[0]).(string)
|
||||
n := int(a[1].(number).Num().Int64())
|
||||
output := []any{}
|
||||
splitted := (strings.SplitN(str, splitby, n))
|
||||
for _, v := range splitted {
|
||||
output = append(output, ArString(v))
|
||||
}
|
||||
return output, ArErr{}
|
||||
}}
|
||||
obj.obj["capitalise"] = builtinFunc{
|
||||
"capitalise",
|
||||
func(a ...any) (any, ArErr) {
|
||||
@@ -418,7 +454,7 @@ func ArString(str string) ArObject {
|
||||
bytes[i] = b.(byte)
|
||||
}
|
||||
str = string(bytes)
|
||||
obj.obj["length"] = len(str)
|
||||
obj.obj["length"] = newNumber().SetUint64(uint64(len(str)))
|
||||
obj.obj["__value__"] = str
|
||||
return nil, ArErr{}
|
||||
}
|
||||
@@ -438,7 +474,7 @@ func ArString(str string) ArObject {
|
||||
bytes[i] = b.(byte)
|
||||
}
|
||||
str = string(bytes)
|
||||
obj.obj["length"] = len(str)
|
||||
obj.obj["length"] = newNumber().SetUint64(uint64(len(str)))
|
||||
obj.obj["__value__"] = str
|
||||
return nil, ArErr{}
|
||||
},
|
||||
@@ -565,7 +601,19 @@ func ArString(str string) ArObject {
|
||||
if typeof(a[0]) != "string" {
|
||||
a[0] = anyToArgon(a[0], false, false, 3, 0, false, 0)
|
||||
}
|
||||
return strings.Join([]string{str, a[0].(string)}, ""), ArErr{}
|
||||
return str + a[0].(string), ArErr{}
|
||||
}}
|
||||
obj.obj["__PostAdd__"] = builtinFunc{
|
||||
"__PostAdd__",
|
||||
func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||
}
|
||||
a[0] = ArValidToAny(a[0])
|
||||
if typeof(a[0]) != "string" {
|
||||
a[0] = anyToArgon(a[0], false, false, 3, 0, false, 0)
|
||||
}
|
||||
return a[0].(string) + str, ArErr{}
|
||||
}}
|
||||
obj.obj["__Multiply__"] = builtinFunc{
|
||||
"__Multiply__",
|
||||
@@ -585,6 +633,18 @@ func ArString(str string) ArObject {
|
||||
}
|
||||
return strings.Repeat(str, int(n.Num().Int64())), ArErr{}
|
||||
}}
|
||||
obj.obj["__NotContains__"] = builtinFunc{
|
||||
"__NotContains__",
|
||||
func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||
}
|
||||
if typeof(a[0]) != "string" {
|
||||
return nil, ArErr{"TypeError", "cannot check if string contains " + typeof(a[0]), 0, "", "", true}
|
||||
}
|
||||
a[0] = ArValidToAny(a[0])
|
||||
return !strings.Contains(str, a[0].(string)), ArErr{}
|
||||
}}
|
||||
obj.obj["__Contains__"] = builtinFunc{
|
||||
"__Contains__",
|
||||
func(a ...any) (any, ArErr) {
|
||||
@@ -627,5 +687,10 @@ func ArString(str string) ArObject {
|
||||
}
|
||||
return ArArray(output), ArErr{}
|
||||
}}
|
||||
obj.obj["__Boolean__"] = builtinFunc{
|
||||
"__Boolean__",
|
||||
func(a ...any) (any, ArErr) {
|
||||
return len(str) > 0, ArErr{}
|
||||
}}
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var timing = anymap{}
|
||||
var timingSync = sync.RWMutex{}
|
||||
|
||||
var ArTerm = Map(anymap{
|
||||
"log": builtinFunc{"log", func(args ...any) (any, ArErr) {
|
||||
@@ -78,7 +80,7 @@ var ArTerm = Map(anymap{
|
||||
}},
|
||||
}),
|
||||
"error": builtinFunc{"error", func(args ...any) (any, ArErr) {
|
||||
output := []any{"error: "}
|
||||
output := []any{}
|
||||
for i := 0; i < len(args); i++ {
|
||||
output = append(output, anyToArgon(args[i], false, true, 3, 0, false, 0))
|
||||
}
|
||||
@@ -87,7 +89,7 @@ var ArTerm = Map(anymap{
|
||||
},
|
||||
},
|
||||
"warn": builtinFunc{"error", func(args ...any) (any, ArErr) {
|
||||
output := []any{"warning: "}
|
||||
output := []any{}
|
||||
for i := 0; i < len(args); i++ {
|
||||
output = append(output, anyToArgon(args[i], false, true, 3, 0, false, 0))
|
||||
}
|
||||
@@ -100,7 +102,9 @@ var ArTerm = Map(anymap{
|
||||
if len(args) > 0 {
|
||||
id = ArValidToAny(args[0])
|
||||
}
|
||||
timingSync.Lock()
|
||||
timing[id] = time.Now()
|
||||
timingSync.Unlock()
|
||||
return nil, ArErr{}
|
||||
},
|
||||
},
|
||||
@@ -109,11 +113,15 @@ var ArTerm = Map(anymap{
|
||||
if len(args) > 0 {
|
||||
id = ArValidToAny(args[0])
|
||||
}
|
||||
timingSync.RLock()
|
||||
if _, ok := timing[id]; !ok {
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot find timer with id '" + fmt.Sprint(id) + "'", EXISTS: true}
|
||||
}
|
||||
timesince := time.Since(timing[id].(time.Time))
|
||||
timingSync.RUnlock()
|
||||
timingSync.Lock()
|
||||
delete(timing, id)
|
||||
timingSync.Unlock()
|
||||
if id == nil {
|
||||
id = "Timer"
|
||||
}
|
||||
@@ -131,11 +139,12 @@ var ArInput = Map(
|
||||
}
|
||||
return ArString(resp), ArErr{}
|
||||
}},
|
||||
"__call__": builtinFunc{"input", func(args ...any) (any, ArErr) {
|
||||
return input(args...), ArErr{}
|
||||
}},
|
||||
"pause": builtinFunc{"pause", func(args ...any) (any, ArErr) {
|
||||
pause()
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
},
|
||||
)
|
||||
|
||||
func init() {
|
||||
ArInput.obj["__call__"] = builtinFunc{"input", func(args ...any) (any, ArErr) {
|
||||
return input(args...), ArErr{}
|
||||
}}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var threadCount = 0
|
||||
var threadChan = make(chan bool)
|
||||
|
||||
func ArThread(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 1, got " + fmt.Sprint(len(args)), EXISTS: true}
|
||||
@@ -26,7 +28,7 @@ func ArThread(args ...any) (any, ArErr) {
|
||||
|
||||
hasrun := false
|
||||
joined := false
|
||||
var wg sync.WaitGroup
|
||||
var wg = make(chan bool)
|
||||
threadMap := Map(anymap{
|
||||
"start": builtinFunc{"start", func(args ...any) (any, ArErr) {
|
||||
if hasrun {
|
||||
@@ -36,10 +38,14 @@ func ArThread(args ...any) (any, ArErr) {
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true}
|
||||
}
|
||||
hasrun = true
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
resp, err = runCall(call{tocall, []any{}, "", 0, ""}, nil, 0)
|
||||
wg.Done()
|
||||
threadCount++
|
||||
resp, err = runCall(call{Callable: tocall, Args: []any{}}, nil, 0)
|
||||
wg <- true
|
||||
threadCount--
|
||||
if threadCount == 0 {
|
||||
threadChan <- true
|
||||
}
|
||||
}()
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
@@ -53,7 +59,7 @@ func ArThread(args ...any) (any, ArErr) {
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true}
|
||||
}
|
||||
joined = true
|
||||
wg.Wait()
|
||||
<-wg
|
||||
return resp, err
|
||||
}},
|
||||
})
|
||||
|
||||
21
src/time.go
21
src/time.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -102,11 +103,14 @@ func ArTimeClass(N time.Time) ArObject {
|
||||
|
||||
var ArTime = Map(anymap{
|
||||
"snooze": builtinFunc{"snooze", func(a ...any) (any, ArErr) {
|
||||
if len(a) > 0 {
|
||||
if len(a) == 1 {
|
||||
float, _ := a[0].(number).Float64()
|
||||
time.Sleep(time.Duration(float*1000000000) * time.Nanosecond)
|
||||
}
|
||||
return nil, ArErr{}
|
||||
return nil, ArErr{
|
||||
TYPE: "Runtime Error",
|
||||
message: "snooze requires 1 argument",
|
||||
}
|
||||
}},
|
||||
"now": builtinFunc{"now", func(a ...any) (any, ArErr) {
|
||||
return ArTimeClass(time.Now()), ArErr{}
|
||||
@@ -129,7 +133,7 @@ var ArTime = Map(anymap{
|
||||
}
|
||||
}
|
||||
return ArTimeClass(N), ArErr{}
|
||||
} else if len(a) > 1 {
|
||||
} else if len(a) == 2 {
|
||||
if typeof(a[0]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "Runtime Error",
|
||||
@@ -163,7 +167,7 @@ var ArTime = Map(anymap{
|
||||
}
|
||||
}},
|
||||
"parseInLocation": builtinFunc{"parseInLocation", func(a ...any) (any, ArErr) {
|
||||
if len(a) != 2 {
|
||||
if len(a) == 2 {
|
||||
if typeof(a[0]) != "string" || typeof(a[1]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "Runtime Error",
|
||||
@@ -191,7 +195,8 @@ var ArTime = Map(anymap{
|
||||
},
|
||||
},
|
||||
"date": builtinFunc{"date", func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
fmt.Println(a, len(a))
|
||||
if len(a) == 1 {
|
||||
if typeof(a[0]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "Runtime Error",
|
||||
@@ -218,7 +223,7 @@ var ArTime = Map(anymap{
|
||||
},
|
||||
},
|
||||
"unix": builtinFunc{"unix", func(a ...any) (any, ArErr) {
|
||||
if len(a) != 2 {
|
||||
if len(a) == 2 {
|
||||
if typeof(a[0]) != "number" || typeof(a[1]) != "number" {
|
||||
return nil, ArErr{
|
||||
TYPE: "Runtime Error",
|
||||
@@ -238,7 +243,7 @@ var ArTime = Map(anymap{
|
||||
},
|
||||
},
|
||||
"unixMilli": builtinFunc{"unixMilli", func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
if len(a) == 1 {
|
||||
if typeof(a[0]) != "number" {
|
||||
return nil, ArErr{
|
||||
TYPE: "Runtime Error",
|
||||
@@ -257,7 +262,7 @@ var ArTime = Map(anymap{
|
||||
},
|
||||
},
|
||||
"unixMicro": builtinFunc{"unixMicro", func(a ...any) (any, ArErr) {
|
||||
if len(a) > 0 {
|
||||
if len(a) == 1 {
|
||||
if typeof(a[0]) != "number" {
|
||||
return nil, ArErr{
|
||||
TYPE: "Runtime Error",
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
)
|
||||
|
||||
func anyToArgon(x any, quote bool, simplify bool, depth int, indent int, colored bool, plain int) string {
|
||||
x = ArValidToAny(x)
|
||||
output := []string{}
|
||||
maybenewline := ""
|
||||
if plain == 1 {
|
||||
@@ -74,6 +73,38 @@ func anyToArgon(x any, quote bool, simplify bool, depth int, indent int, colored
|
||||
if colored {
|
||||
output = append(output, "\x1b[0m")
|
||||
}
|
||||
case ArObject:
|
||||
if callable, ok := x.obj["__string__"]; ok && !quote {
|
||||
val, err := runCall(
|
||||
call{
|
||||
Callable: callable,
|
||||
Args: []any{},
|
||||
},
|
||||
stack{},
|
||||
0,
|
||||
)
|
||||
if !err.EXISTS {
|
||||
output = append(output, anyToArgon(val, false, simplify, depth, indent, colored, plain))
|
||||
break
|
||||
}
|
||||
} else if callable, ok := x.obj["__repr__"]; ok {
|
||||
val, err := runCall(
|
||||
call{
|
||||
Callable: callable,
|
||||
Args: []any{},
|
||||
},
|
||||
stack{},
|
||||
0,
|
||||
)
|
||||
if !err.EXISTS {
|
||||
output = append(output, anyToArgon(val, false, simplify, depth, indent, colored, plain))
|
||||
break
|
||||
}
|
||||
} else if val, ok := x.obj["__value__"]; ok {
|
||||
output = append(output, anyToArgon(val, quote, simplify, depth, indent, colored, plain))
|
||||
break
|
||||
}
|
||||
output = append(output, "<object>")
|
||||
case anymap:
|
||||
if len(x) == 0 {
|
||||
return "{}"
|
||||
|
||||
175
src/translate.go
175
src/translate.go
@@ -11,48 +11,109 @@ type UNPARSEcode struct {
|
||||
path string
|
||||
}
|
||||
|
||||
var knownFailures = map[string]ArErr{}
|
||||
|
||||
func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine int) (any, bool, ArErr, int) {
|
||||
if knownErr, ok := knownFailures[code.code]; ok {
|
||||
return nil, false, ArErr{
|
||||
knownErr.TYPE,
|
||||
knownErr.message,
|
||||
code.line,
|
||||
code.path,
|
||||
code.realcode,
|
||||
true,
|
||||
}, 1
|
||||
}
|
||||
var (
|
||||
resp any = nil
|
||||
worked bool = false
|
||||
err ArErr = ArErr{"Syntax Error", "invalid syntax", code.line, code.path, code.realcode, true}
|
||||
i int = 1
|
||||
)
|
||||
if isLine == 2 {
|
||||
if isDeleteVariable(code) {
|
||||
return parseDelete(code, index, codelines)
|
||||
} else if isComment(code) {
|
||||
if isLine == 3 {
|
||||
if isComment(code) {
|
||||
resp, worked, err, i = parseComment(code, index, codelines)
|
||||
if worked {
|
||||
return resp, worked, err, i
|
||||
}
|
||||
} else if isReturn(code) {
|
||||
return parseReturn(code, index, codelines)
|
||||
} else if isBreak(code) {
|
||||
return parseBreak(code)
|
||||
} else if isContinue(code) {
|
||||
return parseContinue(code)
|
||||
} else if isIfStatement(code) {
|
||||
return parseIfStatement(code, index, codelines)
|
||||
resp, worked, err, i = parseIfStatement(code, index, codelines)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
} else if isWhileLoop(code) {
|
||||
return parseWhileLoop(code, index, codelines)
|
||||
resp, worked, err, i = parseWhileLoop(code, index, codelines)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
} else if isForeverLoop(code) {
|
||||
return parseForeverLoop(code, index, codelines)
|
||||
resp, worked, err, i = parseForeverLoop(code, index, codelines)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
} else if isForLoop(code) {
|
||||
return parseForLoop(code, index, codelines)
|
||||
resp, worked, err, i = parseForLoop(code, index, codelines)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
} else if isGenericImport(code) {
|
||||
return parseGenericImport(code, index, codelines)
|
||||
resp, worked, err, i = parseGenericImport(code, index, codelines)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
} else if isTryCatch(code) {
|
||||
return parseTryCatch(code, index, codelines)
|
||||
resp, worked, err, i = parseTryCatch(code, index, codelines)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
}
|
||||
if isLine >= 1 {
|
||||
if isDoWrap(code) {
|
||||
return parseDoWrap(code, index, codelines)
|
||||
return resp, worked, err, i
|
||||
}
|
||||
}
|
||||
|
||||
if isLine == 2 {
|
||||
if isLine >= 2 {
|
||||
if isReturn(code) {
|
||||
resp, worked, err, i = parseReturn(code, index, codelines)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
} else if isBreak(code) {
|
||||
resp, worked, err, i = parseBreak(code)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
} else if isContinue(code) {
|
||||
resp, worked, err, i = parseContinue(code)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
} else if isDeleteVariable(code) {
|
||||
resp, worked, err, i = parseDelete(code, index, codelines)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
}
|
||||
}
|
||||
|
||||
if isLine >= 1 {
|
||||
if isDoWrap(code) {
|
||||
resp, worked, err, i = parseDoWrap(code, index, codelines)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
}
|
||||
}
|
||||
|
||||
if isLine > 1 {
|
||||
isLine = 1
|
||||
}
|
||||
|
||||
@@ -70,9 +131,6 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
||||
return resp, worked, err, i
|
||||
}
|
||||
}
|
||||
if isnot(code) {
|
||||
return parseNot(code, index, codelines, isLine)
|
||||
}
|
||||
if isSetVariable(code) {
|
||||
resp, worked, err, i = parseSetVariable(code, index, codelines, isLine)
|
||||
if worked {
|
||||
@@ -86,25 +144,46 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
||||
}
|
||||
}
|
||||
if isNumber(code) {
|
||||
return parseNumber(code)
|
||||
resp, worked, err, i = parseNumber(code)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
} else if isString(code) {
|
||||
return parseString(code)
|
||||
resp, worked, err, i = parseString(code)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
} else if issquareroot(code) {
|
||||
return parseSquareroot(code, index, codelines)
|
||||
} else if isFactorial(code) {
|
||||
return parseFactorial(code, index, codelines)
|
||||
resp, worked, err, i = parseSquareroot(code, index, codelines)
|
||||
if worked {
|
||||
return resp, worked, err, i
|
||||
}
|
||||
}
|
||||
if isFactorial(code) {
|
||||
resp, worked, err, i = parseFactorial(code, index, codelines)
|
||||
if worked {
|
||||
return resp, worked, err, i
|
||||
}
|
||||
}
|
||||
if isVariable(code) {
|
||||
return parseVariable(code)
|
||||
resp, worked, err, i = parseVariable(code)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
}
|
||||
if isArray(code) {
|
||||
resp, worked, err, i = parseArray(code, index, codelines)
|
||||
if worked {
|
||||
return resp, worked, err, i
|
||||
}
|
||||
} else if isMap(code) {
|
||||
resp, worked, err, i = parseMap(code, index, codelines)
|
||||
}
|
||||
if isCall(code) {
|
||||
resp, worked, err, i = parseCall(code, index, codelines)
|
||||
if isnot(code) {
|
||||
resp, worked, err, i = parseNot(code, index, codelines, isLine)
|
||||
if worked {
|
||||
return resp, worked, err, i
|
||||
}
|
||||
@@ -117,16 +196,33 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
||||
return nil, worked, err, step
|
||||
}
|
||||
}
|
||||
if isCall(code) {
|
||||
resp, worked, err, i = parseCall(code, index, codelines)
|
||||
if worked {
|
||||
return resp, worked, err, i
|
||||
}
|
||||
}
|
||||
if isNegative(code) {
|
||||
return parseNegative(code, index, codelines)
|
||||
resp, worked, err, i = parseNegative(code, index, codelines)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
} else if isMapGet(code) {
|
||||
return mapGetParse(code, index, codelines)
|
||||
resp, worked, err, i = mapGetParse(code, index, codelines)
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
} else if isIndexGet(code) {
|
||||
resp, worked, err, i = indexGetParse(code, index, codelines)
|
||||
if worked {
|
||||
return resp, worked, err, i
|
||||
}
|
||||
}
|
||||
if !worked {
|
||||
knownFailures[code.code] = err
|
||||
}
|
||||
return resp, worked, err, i
|
||||
}
|
||||
|
||||
@@ -141,15 +237,16 @@ func translate(codelines []UNPARSEcode) ([]any, ArErr) {
|
||||
if currentindent != 0 {
|
||||
return nil, ArErr{"Syntax Error", "invalid indent", codelines[i].line, codelines[i].path, codelines[i].realcode, true}
|
||||
}
|
||||
val, _, err, step := translateVal(codelines[i], i, codelines, 2)
|
||||
switch val.(type) {
|
||||
case CallReturn:
|
||||
return nil, ArErr{"Runtime Error", "Jump statment at top level", codelines[i].line, codelines[i].path, codelines[i].realcode, true}
|
||||
}
|
||||
val, _, err, step := translateVal(codelines[i], i, codelines, 3)
|
||||
i += step
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
err = translateThrowOnNonLoop(val)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
translated = append(translated, val)
|
||||
}
|
||||
return translated, ArErr{}
|
||||
|
||||
@@ -57,7 +57,7 @@ func parseTryCatch(code UNPARSEcode, index int, codelines []UNPARSEcode) (TryCat
|
||||
}
|
||||
|
||||
func runTryCatch(t TryCatch, stack stack, stacklevel int) (any, ArErr) {
|
||||
val, err := runVal(t.Try, stack, stacklevel)
|
||||
val, err := runVal(t.Try, stack, stacklevel+1)
|
||||
if err.EXISTS {
|
||||
vars := anymap{}
|
||||
vars[t.errorName] = Map(anymap{
|
||||
@@ -67,7 +67,7 @@ func runTryCatch(t TryCatch, stack stack, stacklevel int) (any, ArErr) {
|
||||
"path": err.path,
|
||||
"code": err.code,
|
||||
})
|
||||
val, err = runVal(t.Catch, append(stack, Map(vars)), stacklevel)
|
||||
val, err = runVal(t.Catch, append(stack, Map(vars)), stacklevel+1)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ func typeof(val any) string {
|
||||
return "function"
|
||||
case builtinFunc:
|
||||
return "function"
|
||||
case byte:
|
||||
return "byte"
|
||||
case []byte:
|
||||
return "buffer"
|
||||
case ArObject:
|
||||
if val, ok := x.obj["__name__"]; ok {
|
||||
val := ArValidToAny(val)
|
||||
|
||||
@@ -37,10 +37,10 @@ var blockedVariableNames = map[string]bool{
|
||||
}
|
||||
|
||||
type accessVariable struct {
|
||||
name string
|
||||
line int
|
||||
code string
|
||||
path string
|
||||
Name string
|
||||
Line int
|
||||
Code string
|
||||
Path string
|
||||
}
|
||||
|
||||
type setVariable struct {
|
||||
@@ -72,7 +72,7 @@ func isVariable(code UNPARSEcode) bool {
|
||||
|
||||
func parseVariable(code UNPARSEcode) (accessVariable, bool, ArErr, int) {
|
||||
name := strings.TrimSpace(code.code)
|
||||
return accessVariable{name: name, code: code.realcode, line: code.line, path: code.path}, true, ArErr{}, 1
|
||||
return accessVariable{Name: name, Code: code.realcode, Line: code.line, Path: code.path}, true, ArErr{}, 1
|
||||
}
|
||||
|
||||
func readVariable(v accessVariable, stack stack) (any, ArErr) {
|
||||
@@ -81,7 +81,7 @@ func readVariable(v accessVariable, stack stack) (any, ArErr) {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
contains, err := builtinCall(callable, []any{v.name})
|
||||
contains, err := builtinCall(callable, []any{v.Name})
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
@@ -90,10 +90,10 @@ func readVariable(v accessVariable, stack stack) (any, ArErr) {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
return builtinCall(callable, []any{v.name})
|
||||
return builtinCall(callable, []any{v.Name})
|
||||
}
|
||||
}
|
||||
return nil, ArErr{"Name Error", "variable \"" + v.name + "\" does not exist", v.line, v.path, v.code, true}
|
||||
return nil, ArErr{"Name Error", "variable \"" + v.Name + "\" does not exist", v.Line, v.Path, v.Code, true}
|
||||
}
|
||||
|
||||
func isSetVariable(code UNPARSEcode) bool {
|
||||
@@ -171,19 +171,47 @@ func parseSetVariable(code UNPARSEcode, index int, lines []UNPARSEcode, isLine i
|
||||
return setVariable{TYPE: "let", toset: toset, value: value, function: function, params: params, line: code.line, code: code.code, path: code.path}, true, ArErr{}, i + namei - 1
|
||||
}
|
||||
|
||||
var operationsToInt = map[byte]int{
|
||||
'+': 10,
|
||||
'-': 11,
|
||||
'*': 12,
|
||||
'/': 15,
|
||||
'^': 16,
|
||||
'&': 0,
|
||||
'|': 1,
|
||||
}
|
||||
|
||||
func parseAutoAsignVariable(code UNPARSEcode, index int, lines []UNPARSEcode, isLine int) (setVariable, bool, ArErr, int) {
|
||||
trim := strings.TrimSpace(code.code)
|
||||
equalsplit := strings.SplitN(trim, "=", 2)
|
||||
name := strings.TrimSpace(equalsplit[0])
|
||||
equalsplit := strings.Split(trim, "=")
|
||||
for i := 1; i < len(equalsplit); i++ {
|
||||
name := strings.TrimSpace(strings.Join(equalsplit[:i], "="))
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
operation := name[len(name)-1]
|
||||
var operationtype int = -1
|
||||
if operation == '+' || operation == '-' || operation == '*' || operation == '/' || operation == '^' || operation == '&' || operation == '|' {
|
||||
name = strings.TrimSpace(name[:len(name)-1])
|
||||
if n, ok := operationsToInt[operation]; ok {
|
||||
operationtype = n
|
||||
}
|
||||
}
|
||||
params := []string{}
|
||||
function := false
|
||||
if blockedVariableNames[name] {
|
||||
if i == len(equalsplit)-1 {
|
||||
return setVariable{}, false, ArErr{"Naming Error", "\"" + name + "\" is a reserved keyword", code.line, code.path, code.realcode, true}, 1
|
||||
}
|
||||
continue
|
||||
}
|
||||
toset, success, err, namei := nameToTranslated(UNPARSEcode{code: name, realcode: code.realcode, line: code.line, path: code.path}, index, lines)
|
||||
if err.EXISTS {
|
||||
if i == len(equalsplit)-1 {
|
||||
return setVariable{}, success, err, namei
|
||||
}
|
||||
continue
|
||||
}
|
||||
switch x := toset.(type) {
|
||||
case accessVariable:
|
||||
break
|
||||
@@ -194,14 +222,28 @@ func parseAutoAsignVariable(code UNPARSEcode, index int, lines []UNPARSEcode, is
|
||||
params = x.params
|
||||
toset = x.toset
|
||||
default:
|
||||
return setVariable{}, false, ArErr{"Type Error", "can't set for non variable, did you mean '=='?", code.line, code.path, code.realcode, true}, 1
|
||||
if i == len(equalsplit)-1 {
|
||||
return setVariable{}, false, ArErr{"Type Error", "can't set for non variable, did you mean to put 'let' before?", code.line, code.path, code.realcode, true}, 1
|
||||
}
|
||||
value, success, err, i := translateVal(UNPARSEcode{code: equalsplit[1], realcode: code.realcode, line: code.line, path: code.path}, index, lines, isLine)
|
||||
continue
|
||||
}
|
||||
value, success, err, i := translateVal(UNPARSEcode{code: strings.Join(equalsplit[i:], "="), realcode: code.realcode, line: code.line, path: code.path}, index, lines, isLine)
|
||||
if !success {
|
||||
return setVariable{}, false, err, i
|
||||
}
|
||||
if operationtype != -1 {
|
||||
value = operationType{
|
||||
operation: operationtype,
|
||||
values: []any{toset, value},
|
||||
line: code.line,
|
||||
code: code.code,
|
||||
path: code.path,
|
||||
}
|
||||
}
|
||||
return setVariable{TYPE: "auto", toset: toset, value: value, function: function, params: params, line: code.line, code: code.code, path: code.path}, true, ArErr{}, i + namei - 1
|
||||
}
|
||||
return setVariable{}, false, ArErr{"Syntax Error", "invalid syntax", code.line, code.path, code.realcode, true}, 1
|
||||
}
|
||||
|
||||
func setVariableValue(v setVariable, stack stack, stacklevel int) (any, ArErr) {
|
||||
var resp any
|
||||
@@ -216,18 +258,22 @@ func setVariableValue(v setVariable, stack stack, stacklevel int) (any, ArErr) {
|
||||
}
|
||||
|
||||
if v.TYPE == "let" {
|
||||
name := v.toset.(accessVariable).Name
|
||||
if v.function {
|
||||
resp = Callable{name, v.params, v.value, v.code, stack, v.line}
|
||||
}
|
||||
stackcallable, ok := stack[len(stack)-1].obj["__setindex__"]
|
||||
if !ok {
|
||||
return nil, ArErr{"Type Error", "stack doesn't have __setindex__", v.line, v.path, v.code, true}
|
||||
}
|
||||
_, err := builtinCall(stackcallable, []any{v.toset.(accessVariable).name, resp})
|
||||
_, err := builtinCall(stackcallable, []any{name, resp})
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
switch x := v.toset.(type) {
|
||||
case accessVariable:
|
||||
name := x.name
|
||||
name := x.Name
|
||||
hasSet := false
|
||||
if v.function {
|
||||
resp = Callable{name, v.params, v.value, v.code, stack, v.line}
|
||||
@@ -263,10 +309,10 @@ func setVariableValue(v setVariable, stack stack, stacklevel int) (any, ArErr) {
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
if len(x.args) != 1 {
|
||||
if len(x.Args) != 1 {
|
||||
return nil, ArErr{"Runtime Error", "cannot set by slice", v.line, v.path, v.code, true}
|
||||
}
|
||||
key, err := runVal(x.args[0], stack, stacklevel+1)
|
||||
key, err := runVal(x.Args[0], stack, stacklevel+1)
|
||||
key = ArValidToAny(key)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
@@ -275,13 +321,12 @@ func setVariableValue(v setVariable, stack stack, stacklevel int) (any, ArErr) {
|
||||
case ArObject:
|
||||
if _, ok := y.obj["__setindex__"]; ok {
|
||||
callable := y.obj["__setindex__"]
|
||||
r := ArValidToAny(resp)
|
||||
_, err := runCall(call{
|
||||
callable: callable,
|
||||
args: []any{key, r},
|
||||
line: v.line,
|
||||
path: v.path,
|
||||
code: v.code,
|
||||
Callable: callable,
|
||||
Args: []any{key, resp},
|
||||
Line: v.line,
|
||||
Path: v.path,
|
||||
Code: v.code,
|
||||
}, stack, stacklevel+1)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
@@ -323,7 +368,7 @@ func runDelete(d ArDelete, stack stack, stacklevel int) (any, ArErr) {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
contains, err := builtinCall(callable, []any{x.name})
|
||||
contains, err := builtinCall(callable, []any{x.Name})
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
@@ -332,19 +377,19 @@ func runDelete(d ArDelete, stack stack, stacklevel int) (any, ArErr) {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
return builtinCall(callable, []any{x.name})
|
||||
return builtinCall(callable, []any{x.Name})
|
||||
}
|
||||
}
|
||||
return nil, ArErr{"Name Error", "variable \"" + x.name + "\" does not exist", d.line, d.path, d.code, true}
|
||||
return nil, ArErr{"Name Error", "variable \"" + x.Name + "\" does not exist", d.line, d.path, d.code, true}
|
||||
case ArMapGet:
|
||||
respp, err := runVal(x.VAL, stack, stacklevel+1)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
if len(x.args) != 1 {
|
||||
if len(x.Args) != 1 {
|
||||
return nil, ArErr{"Runtime Error", "can't delete by slice", d.line, d.path, d.code, true}
|
||||
}
|
||||
key, err := runVal(x.args[0], stack, stacklevel+1)
|
||||
key, err := runVal(x.Args[0], stack, stacklevel+1)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
221
src/wasm.go
221
src/wasm.go
@@ -1,221 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"syscall/js"
|
||||
)
|
||||
|
||||
func argonToJsValid(argon any) any {
|
||||
switch x := argon.(type) {
|
||||
case number:
|
||||
f, _ := x.Float64()
|
||||
return f
|
||||
case ArObject:
|
||||
if typeof(x) == "array" {
|
||||
arr := js.Global().Get("Array").New()
|
||||
for i, v := range x.obj["__value__"].([]any) {
|
||||
arr.SetIndex(i, argonToJsValid(v))
|
||||
}
|
||||
return arr
|
||||
} else if typeof(x) == "string" {
|
||||
return x.obj["__value__"].(string)
|
||||
}
|
||||
|
||||
obj := js.Global().Get("Object").New()
|
||||
for k, v := range x.obj {
|
||||
obj.Set(anyToArgon(k, false, false, 3, 0, false, 0), argonToJsValid(v))
|
||||
}
|
||||
return obj
|
||||
case bool, string:
|
||||
return x
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func wasmRun(code string, allowDocument bool) (any, ArErr) {
|
||||
JSclearTimers()
|
||||
initRandom()
|
||||
global := makeGlobal(allowDocument)
|
||||
lines := strings.Split(code, "\n")
|
||||
codelines := []UNPARSEcode{}
|
||||
for i := 0; i < len(lines); i++ {
|
||||
codelines = append(codelines, UNPARSEcode{
|
||||
lines[i],
|
||||
lines[i],
|
||||
i + 1,
|
||||
"<wasm>",
|
||||
})
|
||||
}
|
||||
|
||||
translated, translationerr := translate(codelines)
|
||||
if translationerr.EXISTS {
|
||||
return nil, translationerr
|
||||
}
|
||||
local := newscope()
|
||||
localvars := Map(anymap{
|
||||
"program": Map(anymap{
|
||||
"args": []any{},
|
||||
"origin": "",
|
||||
"import": builtinFunc{"import", func(args ...any) (any, ArErr) {
|
||||
return nil, ArErr{"Import Error", "Cannot Import in WASM", 0, "<wasm>", "", true}
|
||||
}},
|
||||
"cwd": "",
|
||||
"exc": "",
|
||||
"file": Map(anymap{
|
||||
"name": "<wasm>",
|
||||
"path": "",
|
||||
}),
|
||||
"main": true,
|
||||
"scope": global,
|
||||
}),
|
||||
})
|
||||
return ThrowOnNonLoop(run(translated, stack{global, localvars, local}))
|
||||
}
|
||||
|
||||
func await(awaitable js.Value) ([]js.Value, []js.Value) {
|
||||
then := make(chan []js.Value)
|
||||
defer close(then)
|
||||
thenFunc := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||
then <- args
|
||||
return nil
|
||||
})
|
||||
defer thenFunc.Release()
|
||||
|
||||
catch := make(chan []js.Value)
|
||||
defer close(catch)
|
||||
catchFunc := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||
catch <- args
|
||||
return nil
|
||||
})
|
||||
defer catchFunc.Release()
|
||||
|
||||
awaitable.Call("then", thenFunc).Call("catch", catchFunc)
|
||||
|
||||
select {
|
||||
case result := <-then:
|
||||
return result, nil
|
||||
case err := <-catch:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var IntervalList = []int{}
|
||||
var TimeoutList = []int{}
|
||||
|
||||
func JSclearTimers() {
|
||||
for _, v := range IntervalList {
|
||||
js.Global().Call("clearInterval", v)
|
||||
}
|
||||
for _, v := range TimeoutList {
|
||||
js.Global().Call("clearTimeout", v)
|
||||
}
|
||||
}
|
||||
|
||||
var ArJS = Map(anymap{
|
||||
"setTimeout": builtinFunc{"setTimeout", func(args ...any) (any, ArErr) {
|
||||
if len(args) > 2 || len(args) < 1 {
|
||||
return nil, ArErr{"TypeError", "Expected 1 or 2 argument, got " + fmt.Sprint(len(args)), 0, "<wasm>", "", true}
|
||||
}
|
||||
if typeof(args[0]) != "function" {
|
||||
return nil, ArErr{"TypeError", "Expected function, got " + typeof(args[0]), 0, "<wasm>", "", true}
|
||||
}
|
||||
var ms int64 = 0
|
||||
if len(args) == 2 {
|
||||
if typeof(args[1]) != "number" {
|
||||
return nil, ArErr{"TypeError", "Expected number, got " + typeof(args[1]), 0, "<wasm>", "", true}
|
||||
}
|
||||
if !args[1].(number).IsInt() {
|
||||
return nil, ArErr{"TypeError", "Expected integer, got float", 0, "<wasm>", "", true}
|
||||
}
|
||||
ms = args[1].(number).Num().Int64()
|
||||
}
|
||||
f := js.FuncOf(func(this js.Value, a []js.Value) interface{} {
|
||||
runCall(
|
||||
call{
|
||||
callable: args[0],
|
||||
args: []any{},
|
||||
},
|
||||
stack{},
|
||||
0,
|
||||
)
|
||||
return nil
|
||||
})
|
||||
n := js.Global().Call("setTimeout", f, ms).Int()
|
||||
TimeoutList = append(TimeoutList, n)
|
||||
return newNumber().SetInt64(int64(n)), ArErr{}
|
||||
}},
|
||||
"setInterval": builtinFunc{"setInterval", func(args ...any) (any, ArErr) {
|
||||
if len(args) > 2 || len(args) < 1 {
|
||||
return nil, ArErr{"TypeError", "Expected 1 or 2 argument, got " + fmt.Sprint(len(args)), 0, "<wasm>", "", true}
|
||||
}
|
||||
if typeof(args[0]) != "function" {
|
||||
return nil, ArErr{"TypeError", "Expected function, got " + typeof(args[0]), 0, "<wasm>", "", true}
|
||||
}
|
||||
var ms int64 = 0
|
||||
if len(args) == 2 {
|
||||
if typeof(args[1]) != "number" {
|
||||
return nil, ArErr{"TypeError", "Expected number, got " + typeof(args[1]), 0, "<wasm>", "", true}
|
||||
}
|
||||
if !args[1].(number).IsInt() {
|
||||
return nil, ArErr{"TypeError", "Expected integer, got float", 0, "<wasm>", "", true}
|
||||
}
|
||||
ms = args[1].(number).Num().Int64()
|
||||
}
|
||||
f := js.FuncOf(func(this js.Value, a []js.Value) interface{} {
|
||||
runCall(
|
||||
call{
|
||||
callable: args[0],
|
||||
args: []any{},
|
||||
},
|
||||
stack{},
|
||||
0,
|
||||
)
|
||||
return nil
|
||||
})
|
||||
n := js.Global().Call("setInterval", f, ms).Int()
|
||||
IntervalList = append(IntervalList, n)
|
||||
return newNumber().SetInt64(int64(n)), ArErr{}
|
||||
}},
|
||||
"clearTimeout": builtinFunc{"clearTimeout", func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{"TypeError", "Expected 1 argument, got " + fmt.Sprint(len(args)), 0, "<wasm>", "", true}
|
||||
}
|
||||
if typeof(args[0]) != "number" {
|
||||
return nil, ArErr{"TypeError", "Expected number, got " + typeof(args[0]), 0, "<wasm>", "", true}
|
||||
}
|
||||
if !args[0].(number).IsInt() {
|
||||
return nil, ArErr{"TypeError", "Expected integer, got float", 0, "<wasm>", "", true}
|
||||
}
|
||||
n := args[0].(number).Num().Int64()
|
||||
for i, v := range TimeoutList {
|
||||
if v == int(n) {
|
||||
TimeoutList = append(TimeoutList[:i], TimeoutList[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
js.Global().Call("clearTimeout", n)
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"clearInterval": builtinFunc{"clearInterval", func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{"TypeError", "Expected 1 argument, got " + fmt.Sprint(len(args)), 0, "<wasm>", "", true}
|
||||
}
|
||||
if typeof(args[0]) != "number" {
|
||||
return nil, ArErr{"TypeError", "Expected number, got " + typeof(args[0]), 0, "<wasm>", "", true}
|
||||
}
|
||||
if !args[0].(number).IsInt() {
|
||||
return nil, ArErr{"TypeError", "Expected integer, got float", 0, "<wasm>", "", true}
|
||||
}
|
||||
n := args[0].(number).Num().Int64()
|
||||
for i, v := range IntervalList {
|
||||
if v == int(n) {
|
||||
IntervalList = append(IntervalList[:i], IntervalList[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
js.Global().Call("clearInterval", n)
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
})
|
||||
@@ -15,7 +15,7 @@ let interpret(code) = do
|
||||
else if (command == '-') do
|
||||
if (pointer not in memory) memory[pointer] = 0
|
||||
memory[pointer] = memory[pointer] - 1
|
||||
else if (command == '.') term.plain.oneLine(chr(memory.get(pointer, 0)), end='')
|
||||
else if (command == '.') term.log((memory.get(pointer, 0)))
|
||||
else if (command == ',') memory[pointer] = ord(input())
|
||||
else if (command == '[') do
|
||||
if (memory.get(pointer, 0) == 0) do
|
||||
@@ -30,5 +30,4 @@ let interpret(code) = do
|
||||
else loops.pop()
|
||||
code_ptr = code_ptr + 1
|
||||
|
||||
|
||||
interpret('>++++++++[<+++++++++>-]<.>++++[<+++++++>-]<+.+++++++..+++.>>++++++[<+++++++>-]<++.------------.>++++++[<+++++++++>-]<+.<.+++.------.--------.>>>++++[<++++++++>-]<+.')
|
||||
interpret('>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>++++++++[<++++>-]<.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+.>++++++++++.')
|
||||
@@ -1,3 +1,5 @@
|
||||
import "csv" as csv
|
||||
import "csv.ar" as csv
|
||||
|
||||
term.log(csv.read("tests/test.csv"))
|
||||
let table = (csv.read("tests/test.csv"))
|
||||
|
||||
term.log(table)
|
||||
14
tests/diff.ar
Normal file
14
tests/diff.ar
Normal file
@@ -0,0 +1,14 @@
|
||||
let zero = 1e-1000
|
||||
let diff(f) = (x) = (f(x + zero) - f(x)) / zero
|
||||
|
||||
|
||||
let f(x) = x^10+x^9+x^8+x^7+x^6+x^5+x^4+x^3+x^2+x+1
|
||||
let x = 100
|
||||
let d = 0
|
||||
|
||||
forever do
|
||||
let n = f(x)
|
||||
term.log("f"+("'"*d)+"("+x+") = "+n)
|
||||
if (n == 0) break
|
||||
f = diff(f)
|
||||
d += 1
|
||||
@@ -1,10 +1,7 @@
|
||||
let getInitials(name) = do
|
||||
name = name.upper()
|
||||
namesplit = name.split(" ")
|
||||
i = 0
|
||||
while (i < namesplit.length) do
|
||||
namesplit[i] = namesplit[i][0]
|
||||
i = i + 1
|
||||
for (i from 0 to namesplit.length) namesplit[i] = namesplit[i][0]
|
||||
return namesplit.join("")
|
||||
|
||||
name = "william bell"
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
f() = do
|
||||
a = []
|
||||
for (i from 0 to 10000) a.append(i)
|
||||
let a = []
|
||||
for (i from 0 to 1000000) a.append(i)
|
||||
|
||||
term.log("start")
|
||||
f()
|
||||
term.log("end")
|
||||
input()
|
||||
24
tests/oop.ar
Normal file
24
tests/oop.ar
Normal file
@@ -0,0 +1,24 @@
|
||||
let toyTank(colour, name) = do
|
||||
let class = {}
|
||||
class.getColour() = do
|
||||
term.log("My colour is", colour)
|
||||
class.getName() = do
|
||||
term.log("My name is", name)
|
||||
class.setColour(newColour) = do
|
||||
colour = newColour
|
||||
class.setName(newName) = do
|
||||
name = newName
|
||||
return class.object()
|
||||
|
||||
|
||||
let tanks = []
|
||||
for (i from 0 to 10) tanks.append(toyTank("red", "tank" + (i+1)))
|
||||
term.log(dir(tanks[0]))
|
||||
for (i from 0 to tanks.length) do
|
||||
tanks[i].getName()
|
||||
tanks[i].getColour()
|
||||
tanks[i].setColour("blue")
|
||||
tanks[i].setName("tank" + (i + 11))
|
||||
tanks[i].getName()
|
||||
tanks[i].getColour()
|
||||
term.log()
|
||||
@@ -1,7 +1,17 @@
|
||||
x = 10
|
||||
let x = 10
|
||||
|
||||
do
|
||||
let x = 20
|
||||
term.log(x)
|
||||
|
||||
term.log(x)
|
||||
|
||||
term.log()
|
||||
|
||||
let x = 10
|
||||
|
||||
do
|
||||
x = 20
|
||||
term.log(x)
|
||||
|
||||
term.log(x)
|
||||
0
tests/testing.ar
Normal file
0
tests/testing.ar
Normal file
@@ -1,9 +0,0 @@
|
||||
term.log(" /\\ |___ \\ ")
|
||||
term.log(" / \\ _ __ __ _ ___ _ __ __ ____) |")
|
||||
term.log(" / /\\ \\ | '__/ _` |/ _ \\| '_ \\ \\ \\ / /__ < ")
|
||||
term.log(" / ____ \\| | | (_| | (_) | | | | \\ V /___) |")
|
||||
term.log(" /_/ \\_\\_| \\__, |\\___/|_| |_| \\_/|____/ ")
|
||||
term.log(" __/ | ")
|
||||
term.log(" |___/ ")
|
||||
term.log("----------------------------------------------")
|
||||
term.log("Welcome to ARGON!")
|
||||
Reference in New Issue
Block a user