add file hashing for cache validation and provide the license to the cc0 files in the project
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -60,4 +60,5 @@ build
|
||||
*.yy.c
|
||||
*.yy.h
|
||||
|
||||
out.arbin
|
||||
out.arbin
|
||||
rand_test.ar
|
||||
4
LICENSE
4
LICENSE
@@ -1,3 +1,7 @@
|
||||
This project is licensed under the GNU General Public License version 3 (GPLv3), except for
|
||||
some files (e.g., in the `src/hash_data/siphash/` directory) which are licensed under CC0 1.0 Universal.
|
||||
See the LICENSE-CC0 file in the respective directories for details.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
|
||||
122
src/hash_data/siphash/LICENSE_CC0
Normal file
122
src/hash_data/siphash/LICENSE_CC0
Normal file
@@ -0,0 +1,122 @@
|
||||
This license applies **only** to the files that explicitly state at the top of the file that they are under CC0 1.0 Universal.
|
||||
|
||||
All other files in this project are licensed under the GNU General Public License version 3 (GPLv3).
|
||||
|
||||
Please refer to the LICENSE file in the root directory for the main project license.
|
||||
|
||||
CC0 1.0 Universal
|
||||
|
||||
Statement of Purpose
|
||||
|
||||
The laws of most jurisdictions throughout the world automatically confer
|
||||
exclusive Copyright and Related Rights (defined below) upon the creator and
|
||||
subsequent owner(s) (each and all, an "owner") of an original work of
|
||||
authorship and/or a database (each, a "Work").
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for the
|
||||
purpose of contributing to a commons of creative, cultural and scientific
|
||||
works ("Commons") that the public can reliably and without fear of later
|
||||
claims of infringement build upon, modify, incorporate in other works, reuse
|
||||
and redistribute as freely as possible in any form whatsoever and for any
|
||||
purposes, including without limitation commercial purposes. These owners may
|
||||
contribute to the Commons to promote the ideal of a free culture and the
|
||||
further production of creative, cultural and scientific works, or to gain
|
||||
reputation or greater distribution for their Work in part through the use and
|
||||
efforts of others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any expectation
|
||||
of additional consideration or compensation, the person associating CC0 with a
|
||||
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
|
||||
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
|
||||
and publicly distribute the Work under its terms, with knowledge of his or her
|
||||
Copyright and Related Rights in the Work and the meaning and intended legal
|
||||
effect of CC0 on those rights.
|
||||
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||
protected by copyright and related or neighboring rights ("Copyright and
|
||||
Related Rights"). Copyright and Related Rights include, but are not limited
|
||||
to, the following:
|
||||
|
||||
i. the right to reproduce, adapt, distribute, perform, display, communicate,
|
||||
and translate a Work;
|
||||
|
||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||
|
||||
iii. publicity and privacy rights pertaining to a person's image or likeness
|
||||
depicted in a Work;
|
||||
|
||||
iv. rights protecting against unfair competition in regards to a Work,
|
||||
subject to the limitations in paragraph 4(a), below;
|
||||
|
||||
v. rights protecting the extraction, dissemination, use and reuse of data in
|
||||
a Work;
|
||||
|
||||
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||
European Parliament and of the Council of 11 March 1996 on the legal
|
||||
protection of databases, and under any national implementation thereof,
|
||||
including any amended or successor version of such directive); and
|
||||
|
||||
vii. other similar, equivalent or corresponding rights throughout the world
|
||||
based on applicable law or treaty, and any national implementations thereof.
|
||||
|
||||
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
||||
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
||||
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
|
||||
and Related Rights and associated claims and causes of action, whether now
|
||||
known or unknown (including existing as well as future claims and causes of
|
||||
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
||||
duration provided by applicable law or treaty (including future time
|
||||
extensions), (iii) in any current or future medium and for any number of
|
||||
copies, and (iv) for any purpose whatsoever, including without limitation
|
||||
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
|
||||
the Waiver for the benefit of each member of the public at large and to the
|
||||
detriment of Affirmer's heirs and successors, fully intending that such Waiver
|
||||
shall not be subject to revocation, rescission, cancellation, termination, or
|
||||
any other legal or equitable action to disrupt the quiet enjoyment of the Work
|
||||
by the public as contemplated by Affirmer's express Statement of Purpose.
|
||||
|
||||
3. Public License Fallback. Should any part of the Waiver for any reason be
|
||||
judged legally invalid or ineffective under applicable law, then the Waiver
|
||||
shall be preserved to the maximum extent permitted taking into account
|
||||
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
|
||||
is so judged Affirmer hereby grants to each affected person a royalty-free,
|
||||
non transferable, non sublicensable, non exclusive, irrevocable and
|
||||
unconditional license to exercise Affirmer's Copyright and Related Rights in
|
||||
the Work (i) in all territories worldwide, (ii) for the maximum duration
|
||||
provided by applicable law or treaty (including future time extensions), (iii)
|
||||
in any current or future medium and for any number of copies, and (iv) for any
|
||||
purpose whatsoever, including without limitation commercial, advertising or
|
||||
promotional purposes (the "License"). The License shall be deemed effective as
|
||||
of the date CC0 was applied by Affirmer to the Work. Should any part of the
|
||||
License for any reason be judged legally invalid or ineffective under
|
||||
applicable law, such partial invalidity or ineffectiveness shall not
|
||||
invalidate the remainder of the License, and in such case Affirmer hereby
|
||||
affirms that he or she will not (i) exercise any of his or her remaining
|
||||
Copyright and Related Rights in the Work or (ii) assert any associated claims
|
||||
and causes of action with respect to the Work, in either case contrary to
|
||||
Affirmer's express Statement of Purpose.
|
||||
|
||||
4. Limitations and Disclaimers.
|
||||
|
||||
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||
surrendered, licensed or otherwise affected by this document.
|
||||
|
||||
b. Affirmer offers the Work as-is and makes no representations or warranties
|
||||
of any kind concerning the Work, express, implied, statutory or otherwise,
|
||||
including without limitation warranties of title, merchantability, fitness
|
||||
for a particular purpose, non infringement, or the absence of latent or
|
||||
other defects, accuracy, or the present or absence of errors, whether or not
|
||||
discoverable, all to the greatest extent permissible under applicable law.
|
||||
|
||||
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||
that may apply to the Work or any use thereof, including without limitation
|
||||
any person's Copyright and Related Rights in the Work. Further, Affirmer
|
||||
disclaims responsibility for obtaining any necessary consents, permissions
|
||||
or other rights required for any use of the Work.
|
||||
|
||||
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||
party to this document and has no duty or obligation with respect to this
|
||||
CC0 or use of the Work.
|
||||
|
||||
For more information, please see
|
||||
<http://creativecommons.org/publicdomain/zero/1.0/>
|
||||
@@ -1,18 +1,22 @@
|
||||
/*
|
||||
SipHash reference C implementation
|
||||
|
||||
Copyright (c) 2012-2022 Jean-Philippe Aumasson
|
||||
<jeanphilippe.aumasson@gmail.com>
|
||||
Copyright (c) 2012-2014 Daniel J. Bernstein <djb@cr.yp.to>
|
||||
|
||||
To the extent possible under law, the author(s) have dedicated all copyright
|
||||
and related and neighboring rights to this software to the public domain
|
||||
worldwide. This software is distributed without any warranty.
|
||||
|
||||
You should have received a copy of the CC0 Public Domain Dedication along
|
||||
with
|
||||
this software. If not, see
|
||||
<http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
* This file is dedicated to the public domain under CC0 1.0 Universal.
|
||||
* See the LICENSE-CC0 file in this directory for details.
|
||||
*
|
||||
* SipHash reference C implementation
|
||||
*
|
||||
* Copyright (c) 2012-2022 Jean-Philippe Aumasson
|
||||
* <jeanphilippe.aumasson@gmail.com>
|
||||
* Copyright (c) 2012-2014 Daniel J. Bernstein <djb@cr.yp.to>
|
||||
*
|
||||
* To the extent possible under law, the author(s) have dedicated all copyright
|
||||
* and related and neighboring rights to this software to the public domain
|
||||
* worldwide. This software is distributed without any warranty.
|
||||
*
|
||||
* You should have received a copy of the CC0 Public Domain Dedication along
|
||||
* with this software. If not, see
|
||||
* <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
*
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
*/
|
||||
|
||||
#include "siphash.h"
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
/*
|
||||
SipHash reference C implementation
|
||||
|
||||
Copyright (c) 2012-2021 Jean-Philippe Aumasson
|
||||
<jeanphilippe.aumasson@gmail.com>
|
||||
Copyright (c) 2012-2014 Daniel J. Bernstein <djb@cr.yp.to>
|
||||
|
||||
To the extent possible under law, the author(s) have dedicated all copyright
|
||||
and related and neighboring rights to this software to the public domain
|
||||
worldwide. This software is distributed without any warranty.
|
||||
|
||||
You should have received a copy of the CC0 Public Domain Dedication along
|
||||
with
|
||||
this software. If not, see
|
||||
<http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
* This file is dedicated to the public domain under CC0 1.0 Universal.
|
||||
* See the LICENSE-CC0 file in this directory for details.
|
||||
*
|
||||
* SipHash reference C implementation
|
||||
*
|
||||
* Copyright (c) 2012-2022 Jean-Philippe Aumasson
|
||||
* <jeanphilippe.aumasson@gmail.com>
|
||||
* Copyright (c) 2012-2014 Daniel J. Bernstein <djb@cr.yp.to>
|
||||
*
|
||||
* To the extent possible under law, the author(s) have dedicated all copyright
|
||||
* and related and neighboring rights to this software to the public domain
|
||||
* worldwide. This software is distributed without any warranty.
|
||||
*
|
||||
* You should have received a copy of the CC0 Public Domain Dedication along
|
||||
* with this software. If not, see
|
||||
* <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
*
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
46
src/main.c
46
src/main.c
@@ -6,6 +6,9 @@
|
||||
#include "runtime/runtime.h"
|
||||
#include "translator/translator.h"
|
||||
|
||||
#include "external/xxhash/xxhash.h"
|
||||
#include "hash_data/hash_data.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <endian.h>
|
||||
#include <locale.h>
|
||||
#include <stdbool.h>
|
||||
@@ -15,15 +18,30 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include "hash_data/hash_data.h"
|
||||
|
||||
const char FILE_IDENTIFIER[] = "ARBI";
|
||||
const uint32_t version_number = 0;
|
||||
|
||||
uint64_t htonll(uint64_t x) {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
return ((uint64_t)htonl(x & 0xFFFFFFFF) << 32) | htonl(x >> 32);
|
||||
#else
|
||||
return x;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t ntohll(uint64_t x) {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
return ((uint64_t)ntohl(x & 0xFFFFFFFF) << 32) | ntohl(x >> 32);
|
||||
#else
|
||||
return x;
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
generate_siphash_key(siphash_key);
|
||||
clock_t start, end;
|
||||
double time_spent, total_time_spent=0;
|
||||
double time_spent, total_time_spent = 0;
|
||||
setlocale(LC_ALL, "");
|
||||
if (argc <= 1)
|
||||
return -1;
|
||||
@@ -34,17 +52,29 @@ int main(int argc, char *argv[]) {
|
||||
darray_init(&tokens, sizeof(Token));
|
||||
|
||||
FILE *file = fopen(path, "r");
|
||||
|
||||
if (!file) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
XXH3_state_t *hash_state = XXH3_createState();
|
||||
XXH3_64bits_reset(hash_state);
|
||||
|
||||
char buffer[8192];
|
||||
size_t bytes;
|
||||
while ((bytes = fread(buffer, 1, sizeof(buffer), file)) > 0) {
|
||||
XXH3_64bits_update(hash_state, buffer, bytes);
|
||||
}
|
||||
rewind(file);
|
||||
uint64_t hash = XXH3_64bits_digest(hash_state);
|
||||
XXH3_freeState(hash_state);
|
||||
printf("Hash: %016llx\n", (unsigned long long)hash);
|
||||
|
||||
LexerState state = {path, file, 0, 0, &tokens};
|
||||
start = clock();
|
||||
lexer(state);
|
||||
end = clock();
|
||||
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
|
||||
total_time_spent+=time_spent;
|
||||
total_time_spent += time_spent;
|
||||
printf("Lexer time taken: %f seconds\n", time_spent);
|
||||
fclose(state.file);
|
||||
|
||||
@@ -56,7 +86,7 @@ int main(int argc, char *argv[]) {
|
||||
parser(path, &ast, &tokens, false);
|
||||
end = clock();
|
||||
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
|
||||
total_time_spent+=time_spent;
|
||||
total_time_spent += time_spent;
|
||||
printf("Parser time taken: %f seconds\n", time_spent);
|
||||
darray_free(&tokens, free_token);
|
||||
|
||||
@@ -66,7 +96,7 @@ int main(int argc, char *argv[]) {
|
||||
translate(&translated, &ast);
|
||||
end = clock();
|
||||
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
|
||||
total_time_spent+=time_spent;
|
||||
total_time_spent += time_spent;
|
||||
printf("Translation time taken: %f seconds\n", time_spent);
|
||||
|
||||
darray_free(&ast, free_parsed);
|
||||
@@ -77,10 +107,12 @@ int main(int argc, char *argv[]) {
|
||||
uint64_t bytecodeSize = (uint64_t)translated.bytecode.size;
|
||||
|
||||
uint32_t version_number_htole32ed = htole32(version_number);
|
||||
uint64_t net_hash = htonll(hash);
|
||||
constantsSize = htole64(constantsSize);
|
||||
bytecodeSize = htole64(bytecodeSize);
|
||||
|
||||
fwrite(&FILE_IDENTIFIER, sizeof(char), strlen(FILE_IDENTIFIER), file);
|
||||
fwrite(&net_hash, sizeof(net_hash), 1, file);
|
||||
fwrite(&version_number_htole32ed, sizeof(uint32_t), 1, file);
|
||||
fwrite(&translated.registerCount, sizeof(uint8_t), 1, file);
|
||||
fwrite(&constantsSize, sizeof(uint64_t), 1, file);
|
||||
@@ -98,7 +130,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
end = clock();
|
||||
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
|
||||
total_time_spent+=time_spent;
|
||||
total_time_spent += time_spent;
|
||||
printf("Execution time taken: %f seconds\n", time_spent);
|
||||
printf("total time taken: %f seconds\n", total_time_spent);
|
||||
|
||||
|
||||
23
src/memory.c
23
src/memory.c
@@ -1,13 +1,9 @@
|
||||
#include "memory.h"
|
||||
#include <gc.h>
|
||||
#include <gc/gc.h>
|
||||
#include <gmp.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> // for malloc/free (temp arena fallback)
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// runtime
|
||||
#include "runtime/objects/type/type.h"
|
||||
|
||||
void *checked_malloc(size_t size) {
|
||||
void *ptr = malloc(size);
|
||||
@@ -19,15 +15,14 @@ void *checked_malloc(size_t size) {
|
||||
}
|
||||
|
||||
void *gmp_gc_realloc(void *ptr, size_t old_size, size_t new_size) {
|
||||
(void)old_size; // Ignore old_size, Boehm doesn't need it
|
||||
return GC_realloc(ptr, new_size);
|
||||
(void)old_size; // Ignore old_size, Boehm doesn't need it
|
||||
return GC_realloc(ptr, new_size);
|
||||
}
|
||||
|
||||
|
||||
void gmp_gc_free(void *ptr, size_t size) {
|
||||
(void)size; // Boehm GC manages this itself
|
||||
// No-op — memory will be collected automatically
|
||||
GC_FREE(ptr);
|
||||
(void)size; // Boehm GC manages this itself
|
||||
// No-op — memory will be collected automatically
|
||||
GC_FREE(ptr);
|
||||
}
|
||||
|
||||
void ar_memory_init() {
|
||||
@@ -35,9 +30,13 @@ void ar_memory_init() {
|
||||
mp_set_memory_functions(GC_malloc, gmp_gc_realloc, gmp_gc_free);
|
||||
}
|
||||
|
||||
|
||||
void *ar_alloc(size_t size) { return GC_MALLOC(size); }
|
||||
|
||||
void ar_finalizer(void *obj, GC_finalization_proc fn, void *client_data,
|
||||
GC_finalization_proc *old_fn, void **old_client_data) {
|
||||
return GC_register_finalizer_no_order(obj, fn, client_data, old_fn, old_client_data);
|
||||
}
|
||||
|
||||
void *ar_alloc_atomic(size_t size) { return GC_MALLOC_ATOMIC(size); }
|
||||
|
||||
char *ar_strdup(const char *str) {
|
||||
|
||||
@@ -2,8 +2,12 @@
|
||||
#define ARGON_MEMORY_H
|
||||
|
||||
#include <stddef.h> // for size_t
|
||||
#include <gc/gc.h>
|
||||
|
||||
// GC-managed allocations
|
||||
|
||||
void ar_finalizer(void *obj, GC_finalization_proc fn, void *client_data,
|
||||
GC_finalization_proc *old_fn, void **old_client_data);
|
||||
void *ar_alloc(size_t size);
|
||||
void *ar_alloc_atomic(size_t size);
|
||||
char *ar_strdup(const char *str);
|
||||
|
||||
@@ -1,36 +1,38 @@
|
||||
#include "object.h"
|
||||
#include "../../memory.h"
|
||||
#include "../../hash_data/hash_data.h"
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "../../memory.h"
|
||||
#include "type/type.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
ArgonObject *BASE_CLASS = NULL;
|
||||
|
||||
void init_base_field() {
|
||||
// add_field(BASE_CLASS, "test", BASE_CLASS);
|
||||
// add_field(BASE_CLASS, "test", BASE_CLASS);
|
||||
}
|
||||
|
||||
ArgonObject* init_child_argon_object(ArgonObject *cls) {
|
||||
ArgonObject *object = init_argon_class(NULL);
|
||||
object->self = object;
|
||||
object->baseObject = cls;
|
||||
add_field(object, "__call__", NULL);
|
||||
return object;
|
||||
ArgonObject *init_child_argon_object(ArgonObject *cls) {
|
||||
ArgonObject *object = init_argon_class(NULL);
|
||||
object->self = object;
|
||||
object->baseObject = cls;
|
||||
add_field(object, "__call__", NULL);
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
ArgonObject* init_argon_class(char*name) {
|
||||
ArgonObject *object = ar_alloc(sizeof(ArgonObject));
|
||||
object->name = name;
|
||||
object->type = TYPE_OBJECT;
|
||||
object->self = NULL;
|
||||
object->baseObject = ARGON_TYPE;
|
||||
object->fields = createHashmap_GC();
|
||||
memset(&object->value, 0, sizeof(object->value));
|
||||
return object;
|
||||
ArgonObject *init_argon_class(char *name) {
|
||||
ArgonObject *object = ar_alloc(sizeof(ArgonObject));
|
||||
object->name = name;
|
||||
object->type = TYPE_OBJECT;
|
||||
object->self = NULL;
|
||||
object->baseObject = ARGON_TYPE;
|
||||
object->fields = createHashmap_GC();
|
||||
memset(&object->value, 0, sizeof(object->value));
|
||||
return object;
|
||||
}
|
||||
|
||||
void add_field(ArgonObject*target, char* name, ArgonObject *object) {
|
||||
hashmap_insert_GC(target->fields, siphash64_bytes(name, strlen(name), siphash_key),name, object, 0);
|
||||
void add_field(ArgonObject *target, char *name, ArgonObject *object) {
|
||||
hashmap_insert_GC(target->fields,
|
||||
siphash64_bytes(name, strlen(name), siphash_key), name,
|
||||
object, 0);
|
||||
}
|
||||
Reference in New Issue
Block a user