changeset 14:b28d7cb60779

checkpoint
author lost
date Thu, 23 Oct 2008 02:44:07 +0000
parents 05d4115b4860
children 1f598d89b9b0
files src/expr.c src/expr.h
diffstat 2 files changed, 88 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/expr.c	Wed Oct 22 04:51:16 2008 +0000
+++ b/src/expr.c	Thu Oct 23 02:44:07 2008 +0000
@@ -23,3 +23,53 @@
 used by LWASM.
 
 */
+
+#include <malloc.h>
+
+#define __expr_c_seen__
+#include "expr.h"
+
+LWVAL *lwval_construct_int(int value)
+{
+	LWVAL *v;
+	
+	v = malloc(sizeof(LWVAL));
+	if (!v)
+		return NULL;
+	
+	v -> lwval_type = LWVAL_TYPE_INT;
+	v -> dt.lwval_int = value;
+	
+	return v;
+}
+
+void lwval_destroy(LWVAL *value)
+{
+	if (value)
+		free(value);
+}
+
+// v1 + v2 -> v3, return v3
+LWVAL *lwval_add(LWVAL *v1, LWVAL *v2, LWVAL *v3)
+{
+}
+
+// v1 - v2 -> v3, return v3
+LWVAL *lwval_sub(LWVAL *v1, LWVAL *v2, LWVAL *v3)
+{
+}
+
+// v1 * v2 -> v3, return v3
+LWVAL *lwval_mul(LWVAL *v1, LWVAL *v2, LWVAL *v3)
+{
+}
+
+// v1 / v2 -> v3, return v3
+LWVAL *lwval_div(LWVAL *v1, LWVAL *v2, LWVAL *v3)
+{
+}
+
+// v1 % v2 -> v3, return v3
+LWVAL *lwval_mod(LWVAL *v1, LWVAL *v2, LWVAL *v3)
+{
+}
--- a/src/expr.h	Wed Oct 22 04:51:16 2008 +0000
+++ b/src/expr.h	Thu Oct 23 02:44:07 2008 +0000
@@ -49,27 +49,47 @@
 an LWVAL may be an expression.
 */
 
-typedef union lwval LWVAL;
-
-struct lwval_int
-{
-	int	lwval_type;					// type of value
-	int lwval_int_value;			// integer value
-};
-
-union lwval
-{
-	struct lwval_int lwval_type_int;	// integer type
-};
-
-enum lwval_types
-{
-	LWVAL_TYPE_INT
-};
-
 #ifndef __expr_h_seen__
 #define __expr_h_seen__
 
+typedef struct lwval LWVAL;
 
+union lwval_dt
+{
+	int lwval_int;					// integer type data
+	char *lwval_var;				// pointer to variable name
+};
+
+enum
+{
+	LWVAL_TYPE_NAN,					// not a number
+	LWVAL_TYPE_INT,					// integer
+	LWVAL_TYPE_VAR,					// variable (symbol)
+	LWVAL_TYPE_EXPR,				// expression
+};
+
+struct lwval
+{
+	int lwval_type;					// data type
+	union lwval_dt dt;				// type specific stuff
+};
+
+#ifndef __expr_c_seen__
+#define EE extern
+#else
+#define EE
+#endif
+
+EE LWVAL *lwval_construct_int(int value);
+EE void lwval_destroy(LWVAL *value);
+
+// operators - operate on v1 and v2 in order, return in v3
+// if v3 is NULL, allocate new LWVAL and return it else just
+// return v3 with new value in it
+EE LWVAL *lwval_add(LWVAL *v1, LWVAL *v2, LWVAL *v3);
+EE LWVAL *lwval_sub(LWVAL *v1, LWVAL *v2, LWVAL *v3);
+EE LWVAL *lwval_mul(LWVAL *v1, LWVAL *v2, LWVAL *v3);
+EE LWVAL *lwval_div(LWVAL *v1, LWVAL *v2, LWVAL *v3);
+EE LWVAL *lwval_mod(LWVAL *v1, LWVAL *v2, LWVAL *v3);
 
 #endif //__expr_h_seen__