]> git.mdlowis.com Git - proto/cerise-c.git/commitdiff
added stubs for hashes and arrays
authorMike Lowis <mike.lowis@gentex.com>
Thu, 13 Jun 2024 20:24:42 +0000 (16:24 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Thu, 13 Jun 2024 20:24:42 +0000 (16:24 -0400)
cerise-c.m
cerise-c.rb
runtime.h

index aa00b710052791c090d9a734a25633431d171e4a..e1b7fa71d912dac54dca63cbf9a319baf774b9c6 100644 (file)
@@ -107,12 +107,12 @@ TestHashOps()
 
 Main()
 {
-    def foo = [1,2,3]
-    def bar = foo
     TestLiterals()
     TestBoolOps()
     TestIntOps()
     TestRealOps()
     TestStringOps()
+    TestArrayOps()
+    TestHashOps()
     return true
 }
index 633bf84e80aaab5b2ae6bd95940f2b32af4c6148..113f15a721ffb642800aae8b2ffd7d78c6a4d923 100755 (executable)
@@ -1153,28 +1153,18 @@ module Codegen
     elsif v.value.is_a? String
       putln state, "Value #{var} = MakeString(#{v.value});"
     elsif v.value.is_a? Array
-      putln state, "Value #{var} = MakeArrayOfLength(#{v.value.length});"
+      putln state, "Value #{var} = MakeArray(#{v.value.length});"
       v.value.each_with_index do |e, i|
         val = emit(state, e)
-        putln state, "Array_SetIndex(#{var}, #{i}, #{val});"
+        putln state, "Array_Set(#{var}, #{i}, #{val});"
 
       end
     elsif v.value.is_a? Hash
-#      putln state,  "Value #{var} = MakeHash(#{v.value});"
-
-      putln state, "Value #{var} = MakeHashOfLength(#{v.value.length});"
+      putln state, "Value #{var} = MakeHash(#{v.value.length});"
       v.value.each do |k, v|
         val = emit(state, v)
-        putln state, "Hash_SetIndex(#{var}, MakeString(#{k.value}), #{val});"
-#
-#
-#        pp k
-#        val = emit(state, e)
-#        putln state, "Array_SetIndex(#{var}, #{i}, #{val});"
-#
+        putln state, "Hash_Set(#{var}, MakeString(#{k.value}), #{val});"
       end
-
-
     else
       raise "code emitting constants of this type not implemented"
     end
@@ -1208,7 +1198,7 @@ module Codegen
       lvar = emit(state, v.left)
       rvar = emit(state, v.right)
       result = mktemp(state);
-      putln state, "Value #{result} = ArrayOrHashGet(#{lvar}, #{rvar});"
+      putln state, "Value #{result} = Object_Get(#{lvar}, #{rvar});"
     else
       lvar = emit(state, v.left)
       rvar = emit(state, v.right)
@@ -1274,7 +1264,7 @@ module Codegen
       object = emit(state, v.name.left)
       key = emit(state, v.name.right)
       value = emit(state, v.value)
-      putln state, "ArrayOrHashSet(#{object}, #{key}, #{value});"
+      putln state, "Object_Set(#{object}, #{key}, #{value});"
     else
       temp = emit(state, v.value)
       raise "invalid local definition: #{v.name.name}" if not state.locals.index(v.name.name)
index 1150cb44b51d764850f8c6b5100c7b0d32927836..c5127803bcb44272fe27a9dd224a9bfe83a4b4d9 100644 (file)
--- a/runtime.h
+++ b/runtime.h
@@ -171,19 +171,25 @@ static inline Value MakeString(char* s) {
     };
 }
 
-//static inline Value MakeRecord(int32_t nslots) {
-//    Value* record = calloc(nslots+1,sizeof(Value));
-//    record[0] = MakeInt(nslots);
-//    return (Value){ .as_uint64 = (NAN_TAG_RECORD | (uintptr_t)record) };
-//}
-//
-//static inline Value MakeArray(int32_t nslots) {
+static inline Value MakeArray(int32_t nslots) {
 //    Value* record = calloc(2,sizeof(Value));
 //    record[0] = MakeInt(1);
 //    record[1] = MakeInt(nslots); //
 //    record[2] = MakeInt(nslots); //
-//    return (Value){ .as_uint64 = (NAN_TAG_RECORD | (uintptr_t)record) };
-//}
+//    return (Value){ .as_uint64 = (NAN_TAG_ARRAY | (uintptr_t)record) };
+    return MakeNil();
+}
+
+
+static inline Value MakeHash(int32_t nslots) {
+//    Value* record = calloc(2,sizeof(Value));
+//    record[0] = MakeInt(1);
+//    record[1] = MakeInt(nslots); //
+//    record[2] = MakeInt(nslots); //
+//    return (Value){ .as_uint64 = (NAN_TAG_ARRAY | (uintptr_t)record) };
+    return MakeNil();
+}
+
 
 /* Value Type Conversions
  *************************************************/
@@ -385,3 +391,33 @@ static inline Value OpNeq(Value left, Value right) {
     }
     return result;
 }
+
+/* Arrays And Hashes
+ *************************************************/
+static void Array_Set(Value array, int index, Value value)
+{
+}
+
+static Value Array_Get(Value array, int index)
+{
+    return MakeNil();
+}
+
+static void Hash_Set(Value hash, Value key, Value value)
+{
+}
+
+static Value Hash_Get(Value hash, Value key)
+{
+    return MakeNil();
+}
+
+static Value Object_Get(Value object, Value key)
+{
+    return MakeNil();
+}
+
+static Value Object_Set(Value object, Value key, Value value)
+{
+    return MakeNil();
+}