Browse Source

Sol Part 47: Powered by Hopes and Dreams!

Graham Northup 5 years ago
parent
commit
e3d2f92b79
4 changed files with 24 additions and 18 deletions
  1. 4
    4
      ast.h
  2. 6
    2
      builtins.c
  3. 2
    2
      sol.h
  4. 12
    10
      state.c

+ 4
- 4
ast.h View File

@@ -24,7 +24,7 @@ typedef struct tag_stmt_node stmt_node;
24 24
  *
25 25
  * Defines the types of literals that may appear in a source program.
26 26
  */
27
-typedef enum {LIT_INT, LIT_FLOAT, LIT_STRING, LIT_NONE} lit_t;
27
+typedef enum {LIT_INT=1024, LIT_FLOAT, LIT_STRING, LIT_NONE} lit_t;
28 28
 /** Literal node
29 29
  *
30 30
  * Represents a literal in a source program.
@@ -42,7 +42,7 @@ typedef struct {
42 42
  *
43 43
  * Defines the types of binary operators that may occur in a source program.
44 44
  */
45
-typedef enum {OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_POW, OP_BAND, OP_BOR, OP_BXOR, OP_LAND, OP_LOR, OP_EQUAL, OP_NEQUAL, OP_LESS, OP_GREATER, OP_LESSEQ, OP_GREATEREQ, OP_LSHIFT, OP_RSHIFT, OP_TBANG} binop_t;
45
+typedef enum {OP_ADD=512, OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_POW, OP_BAND, OP_BOR, OP_BXOR, OP_LAND, OP_LOR, OP_EQUAL, OP_NEQUAL, OP_LESS, OP_GREATER, OP_LESSEQ, OP_GREATEREQ, OP_LSHIFT, OP_RSHIFT, OP_TBANG} binop_t;
46 46
 /** Binary operation node
47 47
  *
48 48
  * Represents a binary operator in a source program.
@@ -57,7 +57,7 @@ typedef struct {
57 57
  *
58 58
  * Defines the types of unary operators that may occur in a source program.
59 59
  */
60
-typedef enum {OP_NEG, OP_BNOT, OP_LNOT, OP_LEN} unop_t;
60
+typedef enum {OP_NEG=768, OP_BNOT, OP_LNOT, OP_LEN} unop_t;
61 61
 /** Unary opreation node
62 62
  *
63 63
  * Represents a unary operator in a source program.
@@ -151,7 +151,7 @@ typedef struct {
151 151
 	stmt_node *loop;
152 152
 } iter_node;
153 153
 
154
-typedef enum {EX_LIT, EX_LISTGEN, EX_MAPGEN, EX_BINOP, EX_UNOP, EX_INDEX, EX_SETINDEX, EX_ASSIGN, EX_REF, EX_CALL, EX_FUNCDECL, EX_IFELSE, EX_LOOP, EX_ITER} expr_t;
154
+typedef enum {EX_LIT=256, EX_LISTGEN, EX_MAPGEN, EX_BINOP, EX_UNOP, EX_INDEX, EX_SETINDEX, EX_ASSIGN, EX_REF, EX_CALL, EX_FUNCDECL, EX_IFELSE, EX_LOOP, EX_ITER} expr_t;
155 155
 typedef struct tag_expr_node {
156 156
 	expr_t type;
157 157
 	loc_t loc;

+ 6
- 2
builtins.c View File

@@ -1571,7 +1571,9 @@ sol_object_t *sol_f_astnode_index(sol_state_t *state, sol_object_t *args) {
1571 1571
 		return sol_set_error_string(state, "Access NULL AST node");
1572 1572
 	}
1573 1573
 	if(sol_is_aststmt(obj)) {
1574
-		if(sol_string_eq(state, str, "type")) {
1574
+		if(sol_string_eq(state, str, "kind")) {
1575
+			res = sol_new_int(state, -1);
1576
+		} else if(sol_string_eq(state, str, "type")) {
1575 1577
 			res = sol_new_int(state, stmt->type);
1576 1578
 		} else if(sol_string_eq(state, str, "loc")) {
1577 1579
 			res = sol_new_map(state);
@@ -1616,7 +1618,9 @@ sol_object_t *sol_f_astnode_index(sol_state_t *state, sol_object_t *args) {
1616 1618
 			}
1617 1619
 		}
1618 1620
 	} else {
1619
-		if(sol_string_eq(state, str, "type")) {
1621
+		if(sol_string_eq(state, str, "kind")) {
1622
+			res = sol_new_int(state, -2);
1623
+		} else if(sol_string_eq(state, str, "type")) {
1620 1624
 			res = sol_new_int(state, expr->type);
1621 1625
 		} else if(sol_string_eq(state, str, "loc")) {
1622 1626
 			res = sol_new_map(state);

+ 2
- 2
sol.h View File

@@ -10,7 +10,7 @@
10 10
 #include "dsl/dsl.h"
11 11
 
12 12
 /** The version of the project, as made available through `debug.version`. */
13
-#define VERSION "0.2a1"
13
+#define VERSION "0.2a2"
14 14
 /** The hexadecimal version of the project, formatted 0xAAIIRPP where:
15 15
  * 
16 16
  * - AA is the two-digit major version
@@ -20,7 +20,7 @@
20 20
  *
21 21
  * This value is guaranteed to always increase by revision.
22 22
  */
23
-#define HEXVER 0x0002A01
23
+#define HEXVER 0x0002A02
24 24
 
25 25
 #ifndef SOL_ICACHE_MIN
26 26
 /** The smallest integer to cache. */

+ 12
- 10
state.c View File

@@ -290,16 +290,16 @@ int sol_state_init(sol_state_t *state) {
290 290
 	sol_map_borrow_name(state, mod, "ST_CONT", sol_new_int(state, ST_CONT));
291 291
 	sol_map_borrow_name(state, mod, "ST_BREAK", sol_new_int(state, ST_BREAK));
292 292
 	sol_map_borrow_name(state, mod, "EX_LIT", sol_new_int(state, EX_LIT));
293
-	sol_map_borrow_name(state, mod, "EX_LISTGEN", sol_new_int(state, EX_LIT));
294
-	sol_map_borrow_name(state, mod, "EX_MAPGEN", sol_new_int(state, EX_LIT));
295
-	sol_map_borrow_name(state, mod, "EX_BINOP", sol_new_int(state, EX_LIT));
296
-	sol_map_borrow_name(state, mod, "EX_UNOP", sol_new_int(state, EX_LIT));
297
-	sol_map_borrow_name(state, mod, "EX_INDEX", sol_new_int(state, EX_LIT));
298
-	sol_map_borrow_name(state, mod, "EX_SETINDEX", sol_new_int(state, EX_LIT));
299
-	sol_map_borrow_name(state, mod, "EX_ASSIGN", sol_new_int(state, EX_LIT));
300
-	sol_map_borrow_name(state, mod, "EX_REF", sol_new_int(state, EX_LIT));
301
-	sol_map_borrow_name(state, mod, "EX_CALL", sol_new_int(state, EX_LIT));
302
-	sol_map_borrow_name(state, mod, "EX_FUNCDECL", sol_new_int(state, EX_LIT));
293
+	sol_map_borrow_name(state, mod, "EX_LISTGEN", sol_new_int(state, EX_LISTGEN));
294
+	sol_map_borrow_name(state, mod, "EX_MAPGEN", sol_new_int(state, EX_MAPGEN));
295
+	sol_map_borrow_name(state, mod, "EX_BINOP", sol_new_int(state, EX_BINOP));
296
+	sol_map_borrow_name(state, mod, "EX_UNOP", sol_new_int(state, EX_UNOP));
297
+	sol_map_borrow_name(state, mod, "EX_INDEX", sol_new_int(state, EX_INDEX));
298
+	sol_map_borrow_name(state, mod, "EX_SETINDEX", sol_new_int(state, EX_SETINDEX));
299
+	sol_map_borrow_name(state, mod, "EX_ASSIGN", sol_new_int(state, EX_ASSIGN));
300
+	sol_map_borrow_name(state, mod, "EX_REF", sol_new_int(state, EX_REF));
301
+	sol_map_borrow_name(state, mod, "EX_CALL", sol_new_int(state, EX_CALL));
302
+	sol_map_borrow_name(state, mod, "EX_FUNCDECL", sol_new_int(state, EX_FUNCDECL));
303 303
 	sol_map_borrow_name(state, mod, "EX_IFELSE", sol_new_int(state, EX_IFELSE));
304 304
 	sol_map_borrow_name(state, mod, "EX_LOOP", sol_new_int(state, EX_LOOP));
305 305
 	sol_map_borrow_name(state, mod, "EX_ITER", sol_new_int(state, EX_ITER));
@@ -330,6 +330,8 @@ int sol_state_init(sol_state_t *state) {
330 330
 	sol_map_borrow_name(state, mod, "LIT_FLOAT", sol_new_int(state, LIT_FLOAT));
331 331
 	sol_map_borrow_name(state, mod, "LIT_STRING", sol_new_int(state, LIT_STRING));
332 332
 	sol_map_borrow_name(state, mod, "LIT_NONE", sol_new_int(state, LIT_NONE));
333
+	sol_map_borrow_name(state, mod, "KIND_STMT", sol_new_int(state, -1));
334
+	sol_map_borrow_name(state, mod, "KIND_EXPR", sol_new_int(state, -2));
333 335
 	sol_map_invert(state, mod);
334 336
 	sol_map_borrow_name(state, mod, "print", sol_new_cfunc(state, sol_f_ast_print));
335 337
 	sol_register_module_name(state, "ast", mod);

Loading…
Cancel
Save