bug fix
This commit is contained in:
@@ -24,3 +24,5 @@ while i < 3;
|
|||||||
|
|
||||||
# ------------------------------------- #
|
# ------------------------------------- #
|
||||||
# ------------------------------------- #
|
# ------------------------------------- #
|
||||||
|
|
||||||
|
print(count());
|
||||||
+15
-13
@@ -1,17 +1,19 @@
|
|||||||
|
|
||||||
/* -- WHAT IS THIS FILE? --
|
/* WHAT IS THIS FILE?
|
||||||
*
|
**
|
||||||
* This file implements the routines that transform the AST
|
** This file implements the routines that transform the AST
|
||||||
* into a list of bytecodes. The functionalities of this file
|
** into a list of bytecodes. The functionalities of this file
|
||||||
* are exposed through the `compile` function, that takes as
|
** are exposed through the `compile` function, that takes as
|
||||||
* input an `AST` and outputs an `Executable`.
|
** input an `AST` and outputs an `Executable`.
|
||||||
* The function that does the heavy lifting is `emit_instr_for_node`
|
**
|
||||||
* which walks the tree and writes instructions to the `ExeBuilder`.
|
** The function that does the heavy lifting is `emit_instr_for_node`
|
||||||
* Some semantic errors are catched at this phase, in which
|
** which walks the tree and writes instructions to the `ExeBuilder`.
|
||||||
* case, they are reported by filling out the `error` structure
|
**
|
||||||
* and aborting. It's also possible that the compilation fails
|
** Some semantic errors are catched at this phase, in which
|
||||||
* bacause of internal errors (which usually means "out of memory").
|
** case, they are reported by filling out the `error` structure
|
||||||
*
|
** and aborting. It's also possible that the compilation fails
|
||||||
|
** bacause of internal errors (which usually means "out of memory").
|
||||||
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|||||||
+25
-23
@@ -1,27 +1,29 @@
|
|||||||
|
|
||||||
/* -- WHAT IS THIS FILE? --
|
/* WHAT IS THIS FILE?
|
||||||
*
|
**
|
||||||
* This file implements the parser of the language, that transforms
|
** This file implements the parser of the language, that transforms
|
||||||
* `Source` objects into `AST` objects. The functionalities of this
|
** `Source` objects into `AST` objects. The functionalities of this
|
||||||
* file are exposed throigh the `parse` function.
|
** file are exposed throigh the `parse` function.
|
||||||
*
|
**
|
||||||
* It's mainly composed by routines that can each parse specific
|
** It's mainly composed by routines that can each parse specific
|
||||||
* parts of a noja source string. For example, `parse_expression`
|
** parts of a noja source string. For example, `parse_expression`
|
||||||
* parses expressions and `parse_while_statement` parses while statements.
|
** parses expressions and `parse_while_statement` parses while statements.
|
||||||
* These functions call each other recursively to parse the source
|
** These functions call each other recursively to parse the source
|
||||||
* and build the abstract syntax tree (AST) that can be then compiled
|
** and build the abstract syntax tree (AST) that can be then compiled
|
||||||
* into bytecode. If at any point the parsing fails because of an
|
** into bytecode. If at any point the parsing fails because of an
|
||||||
* external or internal error, then the error is reported and the parsing
|
** external or internal error, then the error is reported and the parsing
|
||||||
* is aborted.
|
** is aborted.
|
||||||
* Since the nodes of the AST always have the same lifetime (they're
|
**
|
||||||
* allocated at the same time and die all together), the allocator
|
** Since the nodes of the AST always have the same lifetime (they're
|
||||||
* scheme of choise is a bump-pointer allocator. This way each of the
|
** allocated at the same time and die all together), the allocator
|
||||||
* parsing routines can allocate memory if it need it but doesn't need
|
** scheme of choise is a bump-pointer allocator. This way each of the
|
||||||
* to free it if an error occurres.
|
** parsing routines can allocate memory if it need it but doesn't need
|
||||||
* The parsing routines don't operate directly on the source text, but
|
** to free it if an error occurres.
|
||||||
* on the tokenized version of it. Before parsing a linked list of
|
**
|
||||||
* tokens is produced through the `tokenize` function.
|
** The parsing routines don't operate directly on the source text, but
|
||||||
*
|
** on the tokenized version of it. Before parsing a linked list of
|
||||||
|
** tokens is produced through the `tokenize` function.
|
||||||
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|||||||
+16
-14
@@ -1,18 +1,20 @@
|
|||||||
|
|
||||||
/* -- WHAT IS THIS FILE? --
|
/* WHAT IS THIS FILE?
|
||||||
*
|
**
|
||||||
* This file implements the routines that serialize the AST
|
** This file implements the routines that serialize the AST
|
||||||
* into JSON format. The JSON manipulation is handled by the
|
** into JSON format. The JSON manipulation is handled by the
|
||||||
* third party library xJSON (written by me, still).
|
** third party library xJSON (written by me, still).
|
||||||
* The serialization functionality is exposed through the
|
**
|
||||||
* `serialize` function, that takes as an `AST` as argument
|
** The serialization functionality is exposed through the
|
||||||
* and outputs a string of valid JSON. Therefore the xJSON
|
** `serialize` function, that takes as an `AST` as argument
|
||||||
* dependency isn't exposed to the caller and can be regarded
|
** and outputs a string of valid JSON. Therefore the xJSON
|
||||||
* as an implementation detail.
|
** dependency isn't exposed to the caller and can be regarded
|
||||||
* The way the serialization occurres is by converting the
|
** as an implementation detail.
|
||||||
* AST's representation native to the compiler to one native
|
**
|
||||||
* to xJSON, an then calling xj_encode on the converted AST.
|
** The way the serialization occurres is by converting the
|
||||||
*
|
** AST's representation native to the compiler to one native
|
||||||
|
** to xJSON, an then calling xj_encode on the converted AST.
|
||||||
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|||||||
@@ -116,8 +116,6 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error)
|
|||||||
// Not the one we wanted.
|
// Not the one we wanted.
|
||||||
}
|
}
|
||||||
|
|
||||||
int old_i = i;
|
|
||||||
|
|
||||||
pert >>= 5;
|
pert >>= 5;
|
||||||
i = (i * 5 + pert + 1) & mask;
|
i = (i * 5 + pert + 1) & mask;
|
||||||
}
|
}
|
||||||
@@ -249,8 +247,6 @@ static _Bool insert(Object *self, Object *key, Object *val, Heap *heap, Error *e
|
|||||||
// Collision.
|
// Collision.
|
||||||
}
|
}
|
||||||
|
|
||||||
int old_i = i;
|
|
||||||
|
|
||||||
pert >>= 5;
|
pert >>= 5;
|
||||||
i = (i * 5 + pert + 1) & mask;
|
i = (i * 5 + pert + 1) & mask;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ static Object *bin_print(Runtime *runtime, Object **argv, unsigned int argc, Err
|
|||||||
|
|
||||||
static Object *bin_count(Runtime *runtime, Object **argv, unsigned int argc, Error *error)
|
static Object *bin_count(Runtime *runtime, Object **argv, unsigned int argc, Error *error)
|
||||||
{
|
{
|
||||||
|
assert(argc == 1);
|
||||||
|
|
||||||
int n = Object_Count(argv[0], error);
|
int n = Object_Count(argv[0], error);
|
||||||
|
|
||||||
if(error->occurred)
|
if(error->occurred)
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ static Object *call(Object *self, Object **argv, unsigned int argc, Heap *heap,
|
|||||||
{
|
{
|
||||||
// Some arguments are missing.
|
// Some arguments are missing.
|
||||||
argv2 = malloc(sizeof(Object*) * expected_argc);
|
argv2 = malloc(sizeof(Object*) * expected_argc);
|
||||||
|
argc2 = expected_argc;
|
||||||
|
|
||||||
if(argv2 == NULL)
|
if(argv2 == NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user