Browse Source

Sol Part 47: Powered by Hopes and Dreams!

master
Graham Northup 6 years ago
parent
commit
e3d2f92b79
  1. 8
      ast.h
  2. 8
      builtins.c
  3. 4
      sol.h
  4. 22
      state.c

8
ast.h

@ -24,7 +24,7 @@ typedef struct tag_stmt_node stmt_node;
*
* Defines the types of literals that may appear in a source program.
*/
typedef enum {LIT_INT, LIT_FLOAT, LIT_STRING, LIT_NONE} lit_t;
typedef enum {LIT_INT=1024, LIT_FLOAT, LIT_STRING, LIT_NONE} lit_t;
/** Literal node
*
* Represents a literal in a source program.
@ -42,7 +42,7 @@ typedef struct {
*
* Defines the types of binary operators that may occur in a source program.
*/
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;
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;
/** Binary operation node
*
* Represents a binary operator in a source program.
@ -57,7 +57,7 @@ typedef struct {
*
* Defines the types of unary operators that may occur in a source program.
*/
typedef enum {OP_NEG, OP_BNOT, OP_LNOT, OP_LEN} unop_t;
typedef enum {OP_NEG=768, OP_BNOT, OP_LNOT, OP_LEN} unop_t;
/** Unary opreation node
*
* Represents a unary operator in a source program.
@ -151,7 +151,7 @@ typedef struct {
stmt_node *loop;
} iter_node;
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;
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;
typedef struct tag_expr_node {
expr_t type;
loc_t loc;

8
builtins.c

@ -1571,7 +1571,9 @@ sol_object_t *sol_f_astnode_index(sol_state_t *state, sol_object_t *args) {
return sol_set_error_string(state, "Access NULL AST node");
}
if(sol_is_aststmt(obj)) {
if(sol_string_eq(state, str, "type")) {
if(sol_string_eq(state, str, "kind")) {
res = sol_new_int(state, -1);
} else if(sol_string_eq(state, str, "type")) {
res = sol_new_int(state, stmt->type);
} else if(sol_string_eq(state, str, "loc")) {
res = sol_new_map(state);
@ -1616,7 +1618,9 @@ sol_object_t *sol_f_astnode_index(sol_state_t *state, sol_object_t *args) {
}
}
} else {
if(sol_string_eq(state, str, "type")) {
if(sol_string_eq(state, str, "kind")) {
res = sol_new_int(state, -2);
} else if(sol_string_eq(state, str, "type")) {
res = sol_new_int(state, expr->type);
} else if(sol_string_eq(state, str, "loc")) {
res = sol_new_map(state);

4
sol.h

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

22
state.c

@ -290,16 +290,16 @@ int sol_state_init(sol_state_t *state) {
sol_map_borrow_name(state, mod, "ST_CONT", sol_new_int(state, ST_CONT));
sol_map_borrow_name(state, mod, "ST_BREAK", sol_new_int(state, ST_BREAK));
sol_map_borrow_name(state, mod, "EX_LIT", sol_new_int(state, EX_LIT));
sol_map_borrow_name(state, mod, "EX_LISTGEN", sol_new_int(state, EX_LIT));
sol_map_borrow_name(state, mod, "EX_MAPGEN", sol_new_int(state, EX_LIT));
sol_map_borrow_name(state, mod, "EX_BINOP", sol_new_int(state, EX_LIT));
sol_map_borrow_name(state, mod, "EX_UNOP", sol_new_int(state, EX_LIT));
sol_map_borrow_name(state, mod, "EX_INDEX", sol_new_int(state, EX_LIT));
sol_map_borrow_name(state, mod, "EX_SETINDEX", sol_new_int(state, EX_LIT));
sol_map_borrow_name(state, mod, "EX_ASSIGN", sol_new_int(state, EX_LIT));
sol_map_borrow_name(state, mod, "EX_REF", sol_new_int(state, EX_LIT));
sol_map_borrow_name(state, mod, "EX_CALL", sol_new_int(state, EX_LIT));
sol_map_borrow_name(state, mod, "EX_FUNCDECL", sol_new_int(state, EX_LIT));
sol_map_borrow_name(state, mod, "EX_LISTGEN", sol_new_int(state, EX_LISTGEN));
sol_map_borrow_name(state, mod, "EX_MAPGEN", sol_new_int(state, EX_MAPGEN));
sol_map_borrow_name(state, mod, "EX_BINOP", sol_new_int(state, EX_BINOP));
sol_map_borrow_name(state, mod, "EX_UNOP", sol_new_int(state, EX_UNOP));
sol_map_borrow_name(state, mod, "EX_INDEX", sol_new_int(state, EX_INDEX));
sol_map_borrow_name(state, mod, "EX_SETINDEX", sol_new_int(state, EX_SETINDEX));
sol_map_borrow_name(state, mod, "EX_ASSIGN", sol_new_int(state, EX_ASSIGN));
sol_map_borrow_name(state, mod, "EX_REF", sol_new_int(state, EX_REF));
sol_map_borrow_name(state, mod, "EX_CALL", sol_new_int(state, EX_CALL));
sol_map_borrow_name(state, mod, "EX_FUNCDECL", sol_new_int(state, EX_FUNCDECL));
sol_map_borrow_name(state, mod, "EX_IFELSE", sol_new_int(state, EX_IFELSE));
sol_map_borrow_name(state, mod, "EX_LOOP", sol_new_int(state, EX_LOOP));
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) {
sol_map_borrow_name(state, mod, "LIT_FLOAT", sol_new_int(state, LIT_FLOAT));
sol_map_borrow_name(state, mod, "LIT_STRING", sol_new_int(state, LIT_STRING));
sol_map_borrow_name(state, mod, "LIT_NONE", sol_new_int(state, LIT_NONE));
sol_map_borrow_name(state, mod, "KIND_STMT", sol_new_int(state, -1));
sol_map_borrow_name(state, mod, "KIND_EXPR", sol_new_int(state, -2));
sol_map_invert(state, mod);
sol_map_borrow_name(state, mod, "print", sol_new_cfunc(state, sol_f_ast_print));
sol_register_module_name(state, "ast", mod);

Loading…
Cancel
Save