]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
Replace slas C code with Scheme code
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 11 Oct 2013 13:57:33 +0000 (09:57 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 11 Oct 2013 13:57:33 +0000 (09:57 -0400)
SConstruct
source/slas/main.c [deleted file]
source/slas/main.scm [new file with mode: 0644]

index 9f4501377df4e38651e18b6379e48fdbbe89a86b..514ac03c3eccc937c2c254d677dd40dac58fb9a5 100644 (file)
@@ -53,6 +53,7 @@ scheme = Environment(
         ENV      = os.environ,
         CCFLAGS  = [ '-explicit-use', '-I', 'inc'],
         LDFLAGS  = [],
+        TOOLS    = [ 'mingw' ],
         BUILDERS = {
             'Program':    scheme_linker,
             'TestRunner': scheme_tester })
@@ -82,7 +83,7 @@ scheme.Program('build/slc', find_files('source/compiler/','*.scm'))
 scheme.Program('build/slpkg', find_files('source/slpkg/','*.scm'))
 
 # SCLPL Assembler
-c_cpp.Program('build/slas', find_files('source/slas/','*.c'))
+scheme.Program('build/slas', find_files('source/slas/','*.scm'))
 
 # SCLPL Virtual Machine
 c_cpp.Program('build/slvm', find_files('source/slvm/','*.c'))
diff --git a/source/slas/main.c b/source/slas/main.c
deleted file mode 100644 (file)
index ebb6f0d..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-#include <stdio.h>
-
-static int assemble_file(char* infile, char* outfile);
-static int generate_bytecode(FILE* ifh, FILE* ofh);
-
-static char usage[] =
-    "\nUsage: slas <INFILE> <OUTFILE>\n\n"
-    "Assemble <INFILE> to SCLPL bytecode and write the result to <OUTFILE>.\n" ;
-
-static char buffer[1024] = { 0 };
-
-int main(int argc, char** argv)
-{
-    int ret = 0;
-    if (argc == 3)
-    {
-        ret = assemble_file(argv[1],argv[2]);
-    }
-    else
-    {
-        puts(usage);
-    }
-    return ret;
-}
-
-static int assemble_file(char* infile, char* outfile)
-{
-    int ret = 1;
-    FILE* ifh = fopen(infile,  "r");
-    FILE* ofh = fopen(outfile, "w");
-    if (ifh && ofh)
-    {
-        ret = generate_bytecode(ifh,ofh);
-    }
-    fclose(ifh);
-    fclose(ofh);
-    fclose(NULL);
-    return ret;
-}
-
-static int generate_bytecode(FILE* ifh, FILE* ofh)
-{
-    int ret = 0;
-    //asm_ctx_t context;
-    //asm_init(&context);
-    while(!feof(ifh))
-    {
-        if (fgets(buffer,1023,ifh))
-        {
-            puts(buffer);
-        }
-        else
-        {
-            ret = 1;
-            break;
-        }
-    }
-    return ret;
-}
-
-
diff --git a/source/slas/main.scm b/source/slas/main.scm
new file mode 100644 (file)
index 0000000..bf7d6f2
--- /dev/null
@@ -0,0 +1,22 @@
+(declare (uses library))
+
+(define usage
+"\nUsage: slas <INFILE> <OUTFILE>
+
+Assemble <INFILE> to SCLPL bytecode and write the result to <OUTFILE>.\n")
+
+; Control Routines
+;------------------------------------------------------------------------------
+(define (assemble-file infile outfile)
+  (define iprt (open-input-file infile))
+  (define oprt (open-output-file outfile))
+  (generate-bytecode iprt oprt))
+
+(define (generate-bytecode iprt oprt) '())
+
+; Main routine
+;------------------------------------------------------------------------------
+(if (= 2 (length (command-line-arguments)))
+    (apply assemble-file (command-line-arguments))
+    (print usage))
+(exit)