WIP: int expressions
authorLukas Krickl <lukas@krickl.dev>
Tue, 14 Nov 2023 17:33:08 +0000 (18:33 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 14 Nov 2023 17:33:08 +0000 (18:33 +0100)
include/ulas.h
src/ulas.c

index a3d51353dabf7e69feb397a01db74ed70a3d9433..cb5b5c90a985aaf9ebeb3923b9bb37ea6df0f760 100644 (file)
@@ -344,4 +344,7 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line,
 int ulas_asmnext(FILE *dst, FILE *src, char *buf, int n);
 int ulas_asm(FILE *dst, FILE *src);
 
+// parses and executes a 32 bit signed int math expressions
+int ulas_intexpr(const char **line, size_t n, int *rc);
+
 #endif
index cea0eb745f113b2b4938f0a6afd59d9f97c25e59..8ef37306f61f2b9869fa6bead4fdbf7145e04d37 100644 (file)
@@ -27,6 +27,10 @@ void ulas_init(struct ulas_config cfg) {
   memset(&ulas, 0, sizeof(ulas));
 
   ulas.tok = ulas_str(8);
+
+  if (cfg.argc) {
+    ulas.filename = cfg.argv[0];
+  }
 }
 
 void ulas_free(void) { ulas_strfree(&ulas.tok); }
@@ -712,8 +716,10 @@ fail:
  * Assembly step
  */
 
+int ulas_intexpr(const char **line, size_t n, int *rc) { return -1; }
+
 int ulas_asmline(FILE *dst, FILE *src, const char *line, size_t n) {
-  // const char *start = line;
+  const char *start = line;
   int rc = 0;
 
   fprintf(dst, "%s", line);
@@ -744,6 +750,21 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, size_t n) {
       goto fail;
     }
 
+    switch (dir) {
+    case ULAS_ASMDIR_NONE:
+    case ULAS_ASMDIR_ORG:
+      ulas.address = ulas_intexpr(&line, strnlen(start, n), &rc);
+      break;
+    case ULAS_ASMDIR_SET:
+    case ULAS_ASMDIR_BYTE:
+    case ULAS_ASMDIR_STR:
+    case ULAS_ASMDIR_FILL:
+    case ULAS_ASMDIR_PAD:
+    case ULAS_ASMDIR_INCBIN:
+      ULASPANIC("asmdir not implemented\n");
+      break;
+    }
+
   } else {
     // is regular line in form of [label:] instruction ; comment
   }