bug fix
This commit is contained in:
@@ -24,3 +24,5 @@ while i < 3;
|
||||
|
||||
# ------------------------------------- #
|
||||
# ------------------------------------- #
|
||||
|
||||
print(count());
|
||||
+16
-14
@@ -1,18 +1,20 @@
|
||||
|
||||
/* -- WHAT IS THIS FILE? --
|
||||
*
|
||||
* This file implements the routines that transform the AST
|
||||
* into a list of bytecodes. The functionalities of this file
|
||||
* are exposed through the `compile` function, that takes as
|
||||
* 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`.
|
||||
* Some semantic errors are catched at this phase, in which
|
||||
* 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").
|
||||
*
|
||||
*/
|
||||
/* WHAT IS THIS FILE?
|
||||
**
|
||||
** This file implements the routines that transform the AST
|
||||
** into a list of bytecodes. The functionalities of this file
|
||||
** are exposed through the `compile` function, that takes as
|
||||
** 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`.
|
||||
**
|
||||
** Some semantic errors are catched at this phase, in which
|
||||
** 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 <setjmp.h>
|
||||
|
||||
+26
-24
@@ -1,28 +1,30 @@
|
||||
|
||||
/* -- WHAT IS THIS FILE? --
|
||||
*
|
||||
* This file implements the parser of the language, that transforms
|
||||
* `Source` objects into `AST` objects. The functionalities of this
|
||||
* file are exposed throigh the `parse` function.
|
||||
*
|
||||
* It's mainly composed by routines that can each parse specific
|
||||
* parts of a noja source string. For example, `parse_expression`
|
||||
* parses expressions and `parse_while_statement` parses while statements.
|
||||
* These functions call each other recursively to parse the source
|
||||
* and build the abstract syntax tree (AST) that can be then compiled
|
||||
* into bytecode. If at any point the parsing fails because of an
|
||||
* external or internal error, then the error is reported and the parsing
|
||||
* 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
|
||||
* scheme of choise is a bump-pointer allocator. This way each of the
|
||||
* parsing routines can allocate memory if it need it but doesn't need
|
||||
* to free it if an error occurres.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/* WHAT IS THIS FILE?
|
||||
**
|
||||
** This file implements the parser of the language, that transforms
|
||||
** `Source` objects into `AST` objects. The functionalities of this
|
||||
** file are exposed throigh the `parse` function.
|
||||
**
|
||||
** It's mainly composed by routines that can each parse specific
|
||||
** parts of a noja source string. For example, `parse_expression`
|
||||
** parses expressions and `parse_while_statement` parses while statements.
|
||||
** These functions call each other recursively to parse the source
|
||||
** and build the abstract syntax tree (AST) that can be then compiled
|
||||
** into bytecode. If at any point the parsing fails because of an
|
||||
** external or internal error, then the error is reported and the parsing
|
||||
** 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
|
||||
** scheme of choise is a bump-pointer allocator. This way each of the
|
||||
** parsing routines can allocate memory if it need it but doesn't need
|
||||
** to free it if an error occurres.
|
||||
**
|
||||
** 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 <string.h>
|
||||
|
||||
+17
-15
@@ -1,19 +1,21 @@
|
||||
|
||||
/* -- WHAT IS THIS FILE? --
|
||||
*
|
||||
* This file implements the routines that serialize the AST
|
||||
* into JSON format. The JSON manipulation is handled by the
|
||||
* third party library xJSON (written by me, still).
|
||||
* The serialization functionality is exposed through the
|
||||
* `serialize` function, that takes as an `AST` as argument
|
||||
* and outputs a string of valid JSON. Therefore the xJSON
|
||||
* dependency isn't exposed to the caller and can be regarded
|
||||
* as an implementation detail.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/* WHAT IS THIS FILE?
|
||||
**
|
||||
** This file implements the routines that serialize the AST
|
||||
** into JSON format. The JSON manipulation is handled by the
|
||||
** third party library xJSON (written by me, still).
|
||||
**
|
||||
** The serialization functionality is exposed through the
|
||||
** `serialize` function, that takes as an `AST` as argument
|
||||
** and outputs a string of valid JSON. Therefore the xJSON
|
||||
** dependency isn't exposed to the caller and can be regarded
|
||||
** as an implementation detail.
|
||||
**
|
||||
** 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 <xjson.h>
|
||||
|
||||
@@ -116,8 +116,6 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error)
|
||||
// Not the one we wanted.
|
||||
}
|
||||
|
||||
int old_i = i;
|
||||
|
||||
pert >>= 5;
|
||||
i = (i * 5 + pert + 1) & mask;
|
||||
}
|
||||
@@ -249,8 +247,6 @@ static _Bool insert(Object *self, Object *key, Object *val, Heap *heap, Error *e
|
||||
// Collision.
|
||||
}
|
||||
|
||||
int old_i = i;
|
||||
|
||||
pert >>= 5;
|
||||
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)
|
||||
{
|
||||
assert(argc == 1);
|
||||
|
||||
int n = Object_Count(argv[0], error);
|
||||
|
||||
if(error->occurred)
|
||||
|
||||
@@ -55,6 +55,7 @@ static Object *call(Object *self, Object **argv, unsigned int argc, Heap *heap,
|
||||
{
|
||||
// Some arguments are missing.
|
||||
argv2 = malloc(sizeof(Object*) * expected_argc);
|
||||
argc2 = expected_argc;
|
||||
|
||||
if(argv2 == NULL)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user